web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Set default dimension for an item from category of a product

(0) ShareShare
ReportReport
Posted on by 1,264

Hello community, 

I have a requirement where i should create financial dimension for an item based on the category of a product.

can you please tell me, if it is possible to do so?

i tried creating the dimension attribute value set like this:

dimensionAttrValSet                     = DimensionAttributeValueSet::find(EcoResProductCategory.Category);

but i wonder if doing this is logical ?

 

might you please helping me figuring this out?

 

Kind regards 

Jihane

*This post is locked for comments

I have the same question (0)
  • Verified answer
    jihane Profile Picture
    1,264 on at
    RE: Set default dimension for an item from category of a product

    Hi here is what the peice of code i used:

    static void CreateDefaultDimensionForItem(Args _args)
    {
        DimensionAttributeValue             dimAttrValue;
        DimensionAttribute                  dimAttr;
        DimensionAttributeValueSetStorage   davss;
        RecId                               defaultDimension;
        EcoResProduct                       Product;
        InventTable                         item;
        EcoResProductCategory               EcoResProductCategory;
    
        //****************************************************
        DimensionDefault                    result;
        RecId                               financialcategoryRecid;
        DimensionValue                      dimensionValue;
        DimensionAliasName                  dimensionAliasName;
    
        DimensionAttributeValueSetStorage   dimStorage = new DimensionAttributeValuesetStorage();
        Product         =   EcoResProduct::findByDisplayProductNumber("MyProduct");
        item            =   InventTable::findByProduct(Product.RecId, true);
    
        dimAttr                 =   DimensionAttribute::findByMIDNumber(6);
        //financialcategoryRecid  =   dimAttr.financialTagCategory();
    
        Select /*Category, Product From*/ EcoResProductCategory
            where EcoResProductCategory.Product ==  Product.RecId;
    
        //dimAttrValue    = DimensionAttributeValue::findByDimensionAttributeAndEntityInst(DimensionAttribute::findByMIDNumber(6).RecId,
          //                                      EcoResProductCategory.Category, true, true);
    
        dimAttrValue    =   DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::findByNumber(6),"MyCategoryValue", true, true);
    
        dimStorage.addItem(dimAttrValue);
        result  = dimStorage.save();
    
        ttsBegin;
            if(item.RecId)
            {
                item.DefaultDimension = result;
                item.update();
            }
        ttsCommit;
        //info(strFmt("%1",dimAttrValue.getEntityInstance()));
    
    
    }


    Thank you Martin and syed for your answers,

    Kind regards

    Jihane

  • Verified answer
    syed baber Profile Picture
    11,633 on at
    RE: Set default dimension for an item from category of a product

    Hi Jihane,

    If you want to replace the specific financial dimension segment from another financial dimension, then take a look at below code which explains this:

    ReplacingFinDimension.jpg

    Please let me know if you have further queries.

    Thanks,

    Baber.

  • jihane Profile Picture
    1,264 on at
    RE: Set default dimension for an item from category of a product

    Yes that is right, My mistake.

    i actually pick up the value from the EcoResProductCategory, like this:

    dimAttrValue    =   DimensionAttributeValue::findByDimensionAttributeAndEntityInst(DimensionAttribute::findByMIDNumber(6).RecId,

                                               EcoResProductCategory.Category, true, true);

       dimStorage.addItem(dimAttrValue);

       result  = dimStorage.save();

       ttsBegin;

           if(item.RecId)

           {

               item.DefaultDimension = result;

               item.doUpdate();

           }  

       ttsCommit;

    but this fills the dimension with wrong values even if dimAttrValue is set with the right elements.

    is there a step i miss before doing this dimStorage.addItem(dimAttrValue);

  • Martin Dráb Profile Picture
    235,966 Most Valuable Professional on at
    RE: Set default dimension for an item from category of a product

    And how DimensionFinancialTag fits into this story? You want values from EcoResProductCategory, don't you? DimensionFinancialTag is used when there is no existing table to take values from.

    I also don't understand what you mean by "dimension combination for the  6th segment". I would say that the default dimension already is a combination of dimensions and your segment should contain a dimension value, not a combination of dimensions.

  • jihane Profile Picture
    1,264 on at
    RE: Set default dimension for an item from category of a product

    i am trying to build the value for my own dimension combination for the  6th segment of

    the dimension,

    and i want to use it as a backing entity for rendering the newly created default dimension.

    Is it the wrong way to build the default dimension?

  • Martin Dráb Profile Picture
    235,966 Most Valuable Professional on at
    RE: Set default dimension for an item from category of a product

    Then look into addItem().

    By the way, can you explain to me what you're trying to do with DimensionFinancialTag? It looks extremely suspicious.

  • jihane Profile Picture
    1,264 on at
    RE: Set default dimension for an item from category of a product

    Hello Martin,

    here the implemented code:

    DimensionDefault                    result;

    DimensionFinancialTag               dimensionFinancialTag;

    RecId                               financialcategoryRecid;

       DimensionValue                      dimensionValue;

       DimensionAliasName                  dimensionAliasName;

       DimensionAttributeValueSetStorage   dimStorage = new DimensionAttributeValuesetStorage();

       Product         =   EcoResProduct::findByDisplayProductNumber("MyProduct");

       item            =   InventTable::findByProduct(Product.RecId, true);

       dimAttr                 =   DimensionAttribute::findByNumber(6);

       financialcategoryRecid  =   dimAttr.financialTagCategory();

       dimAttrValue    =   DimensionAttributeValue::findByDimensionAttributeAndEntityInst(DimensionAttribute::findByNumber(6).RecId, financialcategoryRecid, true, true);

       dimensionFinancialTag.value = MyValue;

       dimensionFinancialTag.FinancialTagCategory  = financialcategoryRecid;

       dimensionFinancialTag.doInsert();

        dimStorage.addItem(dimAttrValue);

       result  = dimStorage.save();

       ttsBegin;

           if(item.RecId)

           {

               item.DefaultDimension = result;

               item.doUpdate();

           }  

       ttsCommit;

    when i am debugging i see that DimAttrValue is set to the right value and dimension, 

    but when i do  dimStorage.addItem(dimAttrValue) to add and save the dimension things go wrong and i end up with the wrong value, 

    is there any other way to use in order to set the default dimension for the item?

    Kind regards

    Jihane

  • Verified answer
    Martin Dráb Profile Picture
    235,966 Most Valuable Professional on at
    RE: Set default dimension for an item from category of a product

    I'm sorry, but I don't know your data, neither I know that dimension value you got.

    If you say that your code

    DimensionAttributeValue::findByDimensionAttributeAndEntityInst(
        DimensionAttribute::findByMIDNumber(6).RecId,
        EcoResProductCategory.Category,
        true,
        true);

    returns a wrong value, then you're probably calling the methods with wrong parameters.

    Use the debugger to see what's going on; especially ensure yourself that your code uses the right attribute. By the way, you should also think about a better way how to identify the attribute to be used for this purpose, e.g. by creating a parameter field.

  • jihane Profile Picture
    1,264 on at
    RE: Set default dimension for an item from category of a product

    Hello martin;

    i proceed as you suggested, and based on this discussion (stackoverflow.com/.../how-to-set-a-single-dimension-value-in-ax-2012) ,

    here is what i am doing:

    DimensionDefault                    result;

       DimensionAttributeValueSetStorage   dimStorage = new DimensionAttributeValuesetStorage();

       Product         =   EcoResProduct::findByDisplayProductNumber("MyProduct");

       item            =   InventTable::findByProduct(Product.RecId, true);

       dimAttr         =   DimensionAttribute::findByNumber(6);

       Select Category, Product From EcoResProductCategory

           where EcoResProductCategory.Product ==  Product.RecId;

       dimAttrValue    =   DimensionAttributeValue::findByDimensionAttributeAndEntityInst(DimensionAttribute::findByMIDNumber(6).RecId, EcoResProductCategory.Category, true, true);

       dimStorage.addItem(dimAttrValue);

       result  = dimStorage.save();

    ttsBegin;

           if(item.RecId)

           {

               item.DefaultDimension = result;

               item.doUpdate();

           }  

       ttsCommit;

    the code above populates the 6th dimension of an article, but it does not bring the suitable value, it actually brings another dimension value,

    is there a way to populate the dimAttrValue with the right data?

    Is there a step missed in the implemented code?

    Thanks a lot for your help,

    Kind regards

    Jihane

  • Suggested answer
    Martin Dráb Profile Picture
    235,966 Most Valuable Professional on at
    RE: Set default dimension for an item from category of a product

    DimensionAttributeValueSet represents the whole set of default dimensions and the find() method expects a RecId of DimensionAttributeValueSet table. Therefore trying to pass the RecId of EcoResCategory table indeed doesn't makes sense.

    I would recommend using DimensionAttributeValueSetStorage class for manipulating with default dimensions. Find the dimension attribute value (create it if needed) by DimensionAttributeValue::findByDimensionAttributeAndEntityInst(), for example, and add it to the storage by find addItem().

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#2
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans