0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dynamics 365 Finance and Operations開発  X++的基礎技巧①

Posted at
1 / 2

在D365FO中,财务维度允许用户跟踪和报告财务数据,而无需更改主账户结构。例如,如果您想要按照项目或成本中心跟踪收入和支出,可以创建相应的财务维度,并在进行会计分录时使用它们。
这里有一个实用的X++代码片段,用于创建一个新的财务维度值:

DimensionAttributeValueSetStorage dimStorage;
DimensionAttribute dimAttr;
DimensionAttributeValue dimAttrValue;
str dimValue = "项目001"; // 您想要创建的财务维度值
;
// 获取或创建财务维度
dimAttr = DimensionAttribute::findByName("项目"); // 替换为您的财务维度名称
if (!dimAttr)
{
throw error("指定的财务维度不存在。");
}
// 使用财务维度名称和值创建新的财务维度值
dimAttrValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttr, dimValue, true, true, true);
// 将新的财务维度值添加到维度值集合中
dimStorage = DimensionAttributeValueSetStorage::findOrCreate(dimAttrValue.DimensionAttributeValueSet, true);
dimStorage.addItem(dimAttrValue.RecId);
// 保存更改
dimStorage.save();
info(strFmt("已成功创建财务维度值 '%1'", dimValue));

使用上述代码可以创建一个名为"项目001"的新财务维度值,然后您可以在会计分录中引用它。记得替换代码中的"项目"和"项目001"为您实际的维度名称和值。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?