Purpose:
Demonstrate how can we get the dimension value owner name in X++.
Application:
Dynamics 365 for Finance and Operations
Business requirement:
Business requirement is to display cost center owner name in a report.
Solution:
We can use the code below to get the cost center dimension value owner in X++.
Code
/// <summary>
/// Get dimension value owner Feb 16, 24 MK
/// </summary>
/// <remarks>
/// Atlas Dynamics Pty Ltd.
/// </remarks>
public RefRecId getDimensionAttributeValueOwner(Name _dimAttrName, DimensionDisplayValue _dimAttrValue)
{
DimensionAttribute dimAttribute;
DimensionAttributeValue dimAttributeValue;
dimAttribute = DimensionAttribute::findByName(_dimAttrName);
dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttribute, _dimAttrValue);
return dimAttributeValue.Owner;
}
We can then call this method in the following way to initialize the temp table buffer.
hcmWorker = HcmWorker::find(this.getDimensionAttributeValueOwner(#CostCenter, purchOrderLineTmp.DimensionCostCenter));
purchOrderLineTmp.DimOwner = hcmWorker.PersonnelNumber;
purchOrderLineTmp.DimOwnerName = hcmWorker.name();