Skip to main content
Post a question

Notifications

Community site session details

Community site session details

Session Id : pvNIt3G/xcNTmIykUwaGXd
Finance | Project Operations, Human Resources, ...
Answered

How can I find the DimensionAttributeValue for a chosen inventTable record

Like (3) ShareShare
ReportReport
Posted on 26 Mar 2025 14:05:52 by 259
I am creating logic to copy a product. For this I also want to copy some underlying data of a product.
 
One thing which I want to copy, is the value of the ItemGroup financial dimension
(shown on the financial dimensions Tab of the released products form)
 
I can find relevant values in the database in the table DimensionAttributeValue,
but I cannot find the link between a certain InventTable record and its DimensionAttributeValue
 
I checked the DimensionEntryControl, which is the formcontrol presented on the Tab of the released products form.
I can see a lot of logic on this form, but I cannot seem to find out where the relation to the inventtable comes into play when building this form and filling it with data.
 
Does anyone know how I can query the relevant dimensionAttributeValue for a given ItemId? (or a EcoResProductRecId, in case the relation is setup via that table)
 
 
Categories:
  • Martin Dráb Profile Picture
    232,262 Most Valuable Professional on 28 Mar 2025 at 16:21:09
    How can I find the DimensionAttributeValue for a chosen inventTable record
    That's surprising, because addItem() calls logic that is supposed to update the value if there already is one for the same attribute.
     
  • Superbunny Profile Picture
    259 on 28 Mar 2025 at 09:50:44
    How can I find the DimensionAttributeValue for a chosen inventTable record
    @Martin Drab:
     
    Ah, I interpreted the way to use the DimensionAttributeValueSetStorage class completely wrong.
     
    I got it working with: 
            DimensionAttribute dimAttr = DimensionAttribute::findByName('ItemGroup');
    
            DimensionAttributeValueSetStorage sourceDimStorage = DimensionAttributeValueSetStorage::find(_templateItemDefaultDimension);
            DimensionAttributeValue attrValueSource = DimensionAttributeValue::find(sourceDimStorage.getValueByDimensionAttribute(dimAttr.RecId));
    
            DimensionAttributeValueSetStorage targetDimStorage = DimensionAttributeValueSetStorage::find(_newItemDefaultDimension);
            DimensionAttributeValue attrValueTarget = DimensionAttributeValue::find(targetDimStorage.getValueByDimensionAttribute(dimAttr.RecId));
            targetDimStorage.removeDimensionAttributeValue(attrValueTarget.RecId);
            targetDimStorage.addItem(attrValueSource);
            DimensionDefault result = targetDimStorage.save();
     
    I had to remove the dimensionvalue first, since it a value for the itemgroup was already assigned.
     
    Thanks a lot for the help, I will mark your reploy as the suggested answer!
  • Verified answer
    Martin Dráb Profile Picture
    232,262 Most Valuable Professional on 27 Mar 2025 at 10:20:12
    How can I find the DimensionAttributeValue for a chosen inventTable record
    Your code doesn't make a good sense to me; I think you want something like this:
    DimensionAttribute dimAttr = DimensionAttribute::find('ItemGroup');
    
    DimensionAttributeValueSetStorage sourceDimStorage = DimensionAttributeValueSetStorage::find(_templateItemDefaultDimension);
    DimensionAttributeValue attrValue = DimensionAttributeValue::find(sourceDimStorage.getValueByDimensionAttribute(dimAttr.RecId));
    
    DimensionAttributeValueSetStorage targetDimStorage = DimensionAttributeValueSetStorage::find(_newItemDefaultDimension);
    targetDimStorage.addItem(attrValue);
    targetDimStorage.save(); // Returns the new default dimension ID
    Note that just calling save() doesn't update InventTable. You need to take its return value, assign it to InventTable.DefaultDimension and save the InventTable record.
  • Superbunny Profile Picture
    259 on 27 Mar 2025 at 08:55:10
    How can I find the DimensionAttributeValue for a chosen inventTable record
    @Martin Drab:
     
    Thank you for your response Martin.
     
    I tried to get it working in the way you said, with the following code:
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionAttributeValueSet dimAttrValueSetTemplateItem = DimensionAttributeValueSet::find(_templateItemDefaultDimension);
    DimensionAttributeValueSetItem  dimAttrValueSetItemTemplateItem;
    
    //Loop through the templateItem's dimensions
    while select  DimensionAttributeValue from dimAttrValueSetItemTemplateItem
        where dimAttrValueSetItemTemplateItem.DimensionAttributeValueSet ==  dimAttrValueSetTemplateItem.RecId
    {
        DimensionAttributeValue dimAttrValueTemplateItem = DimensionAttributeValue::find(dimAttrValueSetItemTemplateItem.DimensionAttributeValue);
        DimensionAttribute dimAttrTemplateItem = DimensionAttribute::find(dimAttrValueTemplateItem.DimensionAttribute);
    
        //Only the itemGroup dimension value should be copied to the new product
        if(dimAttrTemplateItem.Name == "ItemGroup")
        {  
            DimensionAttributeValueSet dimAttrValueSetNewItem = DimensionAttributeValueSet::find(_newItemDefaultDimension);
            DimensionAttributeValueSetItem  dimAttrValueSetItemNewItem;
    
            //Loop through the new item's dimensions
            while select DimensionAttributeValue from dimAttrValueSetItemNewItem
                where dimAttrValueSetItemNewItem.DimensionAttributeValueSet ==  dimAttrValueSetNewItem.RecId
            {
                DimensionAttributeValue dimAttrValueNewItem = DimensionAttributeValue::find(dimAttrValueSetItemNewItem.DimensionAttributeValue);
                DimensionAttribute dimAttrNewItem = DimensionAttribute::find(dimAttrValueNewItem.DimensionAttribute);
                
                if(dimAttrNewItem.Name == "ItemGroup")
                {
                    //Copy template items dimension value to the new items dimension value
                    dimAttrValueNewItem.DisplayValue = dimAttrValueTemplateItem.DisplayValue;
                    valueSetStorage.addItem(dimAttrValueNewItem);
                }
            }
        }
    }
     
    As you can see I loop through the original item (template Item) to find the itemGroup-dimensions value which I want to add to the itemGroup-dimension of my new item.
     
    I debugged this code and I can see the correct records are being found. 
    I can also see that the line 'dimAttrValueNewItem.DisplayValue = dimAttrValueTemplateItem.DisplayValue;'
    truly assigns the templateItems' dimensionvalue to the newItems dimensionvalue. 
     
    However, in the client I still see the old dimensionvalue showing up for the new item.
    So the valueSetStorage.AddItem method does not really seem to persist my data change. Should I call some other update method or what am I doing wrong here?
  • Martin Dráb Profile Picture
    232,262 Most Valuable Professional on 26 Mar 2025 at 14:31:04
    How can I find the DimensionAttributeValue for a chosen inventTable record
    InventTable has DefaultDimension field, which stores a reference to the combination of all its dimensions.
     
    Rather then digging to details of the data model, you can use DimensionAttributeValueSetStorage class to work on a higher level of abstraction. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,333 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,262 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans
Loading started