如何在AX 2012中设置单个尺寸值? [英] How to set a single dimension value in AX 2012?

查看:95
本文介绍了如何在AX 2012中设置单个尺寸值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是设置一些从外部来源读取的尺寸值.

My problem is setting some dimension values read from an external source.

鉴于AX 2009声明:

Given the AX 2009 statement:

ledgerJournalTrans.Dimension    = ledgerTable.Dimension;
ledgerJournalTrans.Dimension[1] = "abc";

与AX 2012中的等效方法是什么?

What is the equivalent way to that in AX 2012?

这将导致存在一个部门"维度作为第一个维度.

This will of cause assume the existence of a "Department" dimension as the first dimension.

推荐答案

首先,AX 2009中的旧维度已完全重做并替换了.新的LedgerDimension是一个组合帐户结构以及基于帐户结构和高级规则结构所需的旧维度值.要了解有关AX 2012中新的维度框架的更多信息,请尝试阅读

First things first, the legacy dimensions in AX 2009 have been completely redone and replaced in AX 2012. The new LedgerDimension are a combination of the account and the old dimension values that are needed based on the account structure and advanced rule structures. To find out more about the new Dimension Framework in AX 2012 try reading the whitepaper about the new dimension framework.

假定Department是第一个维度,并且两个维度都使用LedgerDimensionAccount EDT可以大大简化此情况,但是新的维度框架非常灵活,因此此假设可能不正确.即使是这样,由于可以设置高级规则结构,因此简单地为Department指定一个新值可能需要对组合的结构进行彻底更改.

Assuming that Department is the first dimension and that both dimensions are using the LedgerDimensionAccount EDT simplifies this scenario quite a bit, but the new dimension framework is very flexible so this assumption may not be correct. Even if it is, simply specifying a new value for Department may require that the structure of the combination needs to change drastically because of advanced rule structures that can be setup.

老实说,我只将下面的代码看作是一些基础知识的演示,而不是在生产中应使用的东西.话虽如此,该代码应该可以实现您想要的,如果使用存储完整组合的LedgerDimensionAccount EDT将LedgerTable上的Dimension字段替换为LedgerDimension字段.

Honestly, I would only consider the code below as just a demonstration how some of the basics work, not something that should be used in production. With that said, this code should accomplish what you want, if that Dimension field on LedgerTable has be replaced with a LedgerDimension field using the LedgerDimensionAccount EDT which stores a full combination.

DimensionStorage dimensionStorage;
DimensionAttribute deparmentDimensionAttribute;
DimensionAttributeValue newDepartmentValue;

// Find the deparment dimension attribute
deparmentDimensionAttribute = DimensionAttribute::findByName("Department");  

// Find the new department value we want to put in the new combination.
newDepartmentValue = DimensionAttributeValue::findByDimensionAttributeAndValue(deparmentDimensionAttribute, "abc");

// Load a DimensionStorage instance with the old combination and update the first segment with new value
dimensionStorage = DimensionStorage::findById(ledgerTable.LedgerDimension);
dimensionStorage.setSegment(1,DimensionStorageSegment::constructFromValue("abc", newDepartmentValue));
ledgerJournalTrans.LedgerDimension = dimensionStorage.save();

这篇关于如何在AX 2012中设置单个尺寸值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆