Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

How to Define Financial Dimensions on Purchase Requisition line Grid

Posted on by 1,272

Hi All,

I have a requirement to be able to insert financial dimensions to the purchase requisition lines through the lines grid instead of going into the details page and inserting through the Financial Dimensions Tab.

At the moment i have added a ledger dimension field on the PurchReqline table and used the LedgerDimensionAccountController to insert a segmented entry on the grid to insert financial dimensions and main account. Now i want to know that if I can add the dimensions selected by the user on the grid (segmented entry) to actual financial dimension tab in the details tab using the DimensionDefaultingController.setDimensionAttributeValue method. I was trying to do so but didn't succeed yet.

Please help me on it and also if there is any other way to fulfill my requirement

  • dynamics developer Profile Picture
    dynamics developer 1,272 on at
    RE: How to Define Financial Dimensions on Purchase Requisition line Grid

    But my client had a requirement to have it on the grid so that he can just tab through the fields like any other while data entry. They were very specific about this.

  • Carlo Severini Profile Picture
    Carlo Severini 95 on at
    RE: How to Define Financial Dimensions on Purchase Requisition line Grid

    Instead of writing code you can move the Financial Dimension FAST TAB from the Detail to the "Header" form (AOT). Tried with Personalization but the client crashes the second time you use the form.

  • Verified answer
    dynamics developer Profile Picture
    dynamics developer 1,272 on at
    RE: How to Define Financial Dimensions on Purchase Requisition line Grid

    Helper Class methods :

    class ebiz_DimensionControllerHelper()

    {

    }

    public DimensionValue getDefaultDimension(RecId defaultDimension, Name dimName)
    {
    DefaultDimensionView defDimensionView;
    select defDimensionView
    where defDimensionView.DefaultDimension==defaultDimension
    && defDimensionView.Name==dimName;

    return defDimensionView.DisplayValue;
    }

    public RecId getNewDefaultDimension(RecId defaultDimension, Name dimName, str 255 dimValue)
    {
    DimensionAttributeValueSetStorage dimStorage;
    Counter i;
    DimensionAttribute dimAttributeDepartment;
    DimensionAttributeValue dimAttributeValue;
    dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);
    dimAttributeDepartment = DimensionAttribute::findByName(dimName);
    if(dimValue)
    {
    dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttributeDepartment, dimValue, true, true);
    dimStorage.addItem(dimAttributeValue);
    }
    else
    dimStorage.removeDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);
    return dimStorage.save();
    }

    public RecId getNewLedgerDimension(RecId ledgerDimension, Name dimName, str 255 dimValue)
    {
    DimensionStorage dimensionStorage;
    DimensionAttribute dimensionAttribute;
    DimensionAttributeValue newDimensionValue;

    // Find the deparment dimension attribute
    dimensionAttribute = DimensionAttribute::findByName(dimName);

    // Find the new department value we want to put in the new combination.
    newDimensionValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, dimValue, true, true);

    // Load a DimensionStorage instance with the old combination and update the first segment with new value
    dimensionStorage = DimensionStorage::findById(ledgerDimension);
    dimensionStorage.setSegment(1,DimensionStorageSegment::constructFromValue(dimValue, newDimensionValue));
    return dimensionStorage.save();
    }

  • Verified answer
    dynamics developer Profile Picture
    dynamics developer 1,272 on at
    RE: How to Define Financial Dimensions on Purchase Requisition line Grid

    Forgot to mention that I used following edit methods for the lookups on  the grid to set the default dimension.

    public edit str 20 editDefaultDimensionDepartment(boolean set, str 20 _department)
    {
        str 20                              department;
        ebiz_DimensionControllerHelper      dimensionController;
    
    
        dimensionController = new ebiz_DimensionControllerHelper();
        if(set)
        {
                this.DefaultDimension   = dimensionController.getNewDefaultDimension(this.DefaultDimension,"Department",_department);
                department             = _department;
        }
        else
        {
                department=dimensionController.getDefaultDimension(this.DefaultDimension,"Department");
        }
    
        return department;
    }
    public edit str 20 editDefaultDimensionMainAccount(boolean set, str 20 _mainAccount)
    {
        str 20                              mainAccount;
        ebiz_DimensionControllerHelper      dimensionController;
    
    
        dimensionController = new ebiz_DimensionControllerHelper();
        if(set)
        {
                this.DefaultDimension   = dimensionController.getNewDefaultDimension(this.DefaultDimension,"MainAccount",_mainAccount);
                mainAccount             = _mainAccount;
        }
        else
        {
                mainAccount=dimensionController.getDefaultDimension(this.DefaultDimension,"MainAccount");
        }
    
        return mainAccount;
    }



  • Verified answer
    dynamics developer Profile Picture
    dynamics developer 1,272 on at
    RE: How to Define Financial Dimensions on Purchase Requisition line Grid

    Hey ALoureiro,

    I did succeed in adding financial dimensions on Requisition Lines but not using segmented entry. Instead I used string fields and made a lookup for the MainAccount and Department dimensions using the following code

    //For the department
    public void lookup()
    {
            SysTableLookup                  sysTableLookup;
            QueryBuildDataSource            queryBuildDataSource,queryBuildDataSource2;
            QueryBuildRange                 queryBuildRange,queryBuildRange2,queryBuildRange3,queryBuildRange4;
            Query                           query = new Query();
    
            sysTableLookup = SysTableLookup::newParameters(tableNum(OMOperatingUnit), Dimension_Department);
            sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, OMOperatingUnitNumber ));
            sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, Name ));
    
            queryBuildDataSource = query.addDataSource(tableNum(OMOperatingUnit));
            queryBuildDataSource.addOrderByField(fieldnum(OMOperatingUnit, OMOperatingUnitNumber));
    
            queryBuildRange=queryBuildDataSource.addRange(fieldNum(OMOperatingUnit,OMOperatingUnitType));
            queryBuildRange.value(enum2Value(OMOperatingUnitType::OMDepartment));
    
            sysTableLookup.parmUseLookupValue(false);
            sysTableLookup.parmQuery(query);
    
    
    
            if (sysTableLookup)
            {
                sysTableLookup.performFormLookup();
            }
    }

    //For the MainAccount
    public void lookup()
    {
            SysTableLookup                  sysTableLookup;
            QueryBuildDataSource            queryBuildDataSource,queryBuildDataSource2;
            QueryBuildRange                 queryBuildRange,queryBuildRange2,queryBuildRange3,queryBuildRange4;
            Query                           query = new Query();
    
            //super();
            sysTableLookup = SysTableLookup::newParameters(tableNum(MainAccount), Dimension_MainAccount);
            sysTableLookup.addLookupfield(fieldNum(MainAccount, MainAccountId ));
            sysTableLookup.addLookupfield(fieldNum(MainAccount, Name ));
    
            queryBuildDataSource = query.addDataSource(tableNum(MainAccount));
            queryBuildDataSource.addOrderByField(fieldnum(MainAccount, MainAccountId));
    
            queryBuildRange=queryBuildDataSource.addRange(fieldNum(MainAccount,LedgerChartOfAccounts));
            queryBuildRange.value("your ledger recid");
    
            sysTableLookup.parmUseLookupValue(false);
            sysTableLookup.parmQuery(query);
    
    
    
            if (sysTableLookup)
            {
                sysTableLookup.performFormLookup();
            }
    }


     I called the form's updateDefaultDimension method at appropriate places to set the default dimension.

    Hope this helps.

    Thanks

  • Suggested answer
    RE: How to Define Financial Dimensions on Purchase Requisition line Grid

    [quote user="dynamics developer"]I have a requirement to be able to insert financial dimensions to the purchase requisition lines through the lines grid instead of going into the details page and inserting through the Financial Dimensions Tab.[/quote]Many people (especially with AX 2009/AX 4.0 experience) have such a wish, but sorry, it doesn't seem to be possible without massive AX customizations.

    [quote user="dynamics developer"]At the moment i have added a ledger dimension field on the PurchReqline table and used the LedgerDimensionAccountController to insert a segmented entry on the grid to insert financial dimensions and main account. Now i want to know that if I can add the dimensions selected by the user on the grid (segmented entry) to actual financial dimension tab in the details tab.[/quote]Those are two different things: DefaultDimension represents just an arbitrary set of dimension attribute values (zero or one value for each attribute); LedgerDimension is a valid dimension attribute value combination. Not all dimension attribute value sets can be valid dimension attribute value combinations depending on your ledger account structures, so it might be not always possible to enter dimension attribute values through a segmented entry control for a desired dimension attribute value set.

    Anyway, you can "parse" your LedgerDimension value "internals" by using DimensionStorage class to get a corresponding DefaultDimension: enumerate segments from 1 to segmentCount(), get dimension attribute id and value for each segment, and then "feed" them to DimensionDefaultingController.setDimensionAttributeValue().

  • ALoureiro Profile Picture
    ALoureiro on at
    RE: How to Define Financial Dimensions on Purchase Requisition line Grid

    Hi there,

    I have a pretty similar requirement.

    Did you succeed with that approach?

    Thanks!

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,420 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans