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)

Override Financial dimensions on Vendor invoice creation

(0) ShareShare
ReportReport
Posted on by 506

I want to change the behaviour of the defaulting of dimension values on the Vendor invoice header when each Purchase order is added to a Vendor invoice.

The customisation has to read all existing dimension values on all PO lines added and based on those values will write certain dimension values on the Invoice header.

Currently in the VendEditInvoice form, the method setHeaderFields() dynamically takes values from the PurchTable and populates the form:

        if (isNonPO)
        {
            dimensionDefaultingControllerHeader.parmAttributeValueSetDataSource(vendInvoiceInfoTable_ds, fieldStr(VendInvoiceInfoTable, DefaultDimension));
//            dimensionDefaultingControllerHeader.setEditability(true);
            dimensionDefaultingControllerHeader.updateValues(NoYesUnchanged::Yes);
        }
        else
        {
            dimensionDefaultingControllerHeader.parmAttributeValueSetDataSource(purchTable_ds, fieldStr(PurchTable, DefaultDimension));
// dimensionDefaultingControllerHeader.setEditability(false); dimensionDefaultingControllerHeader.updateValues(NoYesUnchanged::No); }


My main question is: What is the best way to customise the existing behaviour in this scenario without compromising existing functionality if possible?

One of my concerns is the method DimensionDefaultingController.parmAttributeValueSetDataSource().

This looks as though it sets up event handlers to respond to any change of financial dimension values on the PO by auto-updating the Vendor Invoice financial dimension values?

I'm unsure how this actually works but presume it only operates for while the form is loaded and before the invoice is saved?

thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    _MGP Profile Picture
    506 on at
    RE: Override Financial dimensions on Vendor invoice creation

    Hi Sukrut,

    In the end I did the call in active() method on the VendInvoiceInfoTable before call to setHeaderFields().

    There was a bit of learning about looping over datasources but got there in the end.

    Thanks for your help.

    Here is rough code listing:

    int active()
    {
        int         ret;
        boolean     paymentSchedEmpty;
        // <GIN>
        boolean     isIndiaCountryRegion = SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIN]);
        // </GIN>
    
        ret = super();
        
        CustomVendInvoiceHelper::checkData(purchTable, vendInvoiceInfoLine_ds);
    
    	...
    	
    }
    	
    	
    	
    public static void checkData(PurchTable _purchTable, FormDataSource _formDataSourceLines)
    {
        boolean                             overrideInvoiceHeader = false;
        
        VendInvoiceInfoLine                 vendInvoiceInfoLine = _formDataSourceLines.getFirst() as VendInvoiceInfoLine;
        
        PurchLine                           purchLine;
        
        int                                 backingEntityTypeSpecialBank;   // Stores the backing entity type for the custom financial dimension
        
        DimensionAttribute                  dimensionAttribute;             //  Contains the financial dimensions records
    
        DimensionAttributeValue             dimensionAttributeValue;        //  Contains used financial dimension values
        
        DefaultDimensionView                ddv;                            
        
        DimensionAttributeValueSetStorage   davss;                          // Manage the saving of updated dimension values
        
        RecId                               defaultDimensionRecId;
        
        
        #macroWithCustomDimensionData
        
    
        backingEntityTypeSpecialBank = tableNum(DimensionFinancialTag);
        
        // Find the Dimension attribute record for the dimension to work on
        select firstonly dimensionAttribute
            where dimensionAttribute.BackingEntityType == backingEntityTypeSpecialBank && dimensionAttribute.Name == #SpecialBank;
        
        dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, #DisplayValueOfCertainSpecialBank, false);
        
        while(vendInvoiceInfoLine)
        {
            // the default dimension is not on the vendInvoiceInfoLine but is on the associated purchLine
            purchLine = vendInvoiceInfoLine.purchLine();
            
            // does the purchLine's financial dimension set include a SpecialBank dimension of value "CertainSpecialBank"?
            select count(RecId) from ddv 
                where
                    ddv.DefaultDimension == purchLine.DefaultDimension &&
                    ddv.DimensionAttributeId == dimensionAttribute.RecId &&
                    ddv.DisplayValue == #DisplayValueOfCertainSpecialBank;
            
            // If there are any lines with a dimension value of CertainSpecialBank override the invoice header to include this value, otherwise keep looking through all lines from all purchase orders added to invoice..
            if(ddv.RecId)
            {
                //info(strFmt('PO Line number: %1, Default dimension: %2, Purch id: %3', vendInvoiceInfoLine.PurchaseLineLineNumber, purchLine.DefaultDimension, _purchTable.PurchId));
                overrideInvoiceHeader = true;
                break;  // break out of the loop and update the PO header
            }
    
            vendInvoiceInfoLine = _formDataSourceLines.getNext() as VendInvoiceInfoLine;
        }
        
        
        if(overrideInvoiceHeader)
        {
            // get (and preserve) the current dimension set assigned on the PO header
            davss = DimensionAttributeValueSetStorage::find(_purchTable.DefaultDimension);
            
            // add CertainSpecialBank value on SpecialBank dimension to the combined dimension value (note that if dimension value already present this doesn't create a new default dimension)
            davss.addItem(dimensionAttributeValue);
            
            // save the combined dimension set and retrieve the default dimension value
            defaultDimensionRecId = davss.save();
            
            if(_purchTable)
            {
                _purchTable.DefaultDimension = defaultDimensionRecId;
                
                // note we are not changing the underlying table (i.e. PO) but essentially temporarily marking this record.
    
                //info('Purchase order/ Vendor invoice header updated');
            }
        }
        
        
    }


  • _MGP Profile Picture
    506 on at
    RE: Override Financial dimensions on Vendor invoice creation

    Hi Sukrut,

    The default behaviour for creating Vendor Invoices by attaching a Purchase order brings through the financial dimensions on the 1st PO's Header onto the Vendor invoice header. This is what I want to customise.

    My main problem is still deciding where best to override the setting of the financial dimension.

    I cannot do it within setHeaderFields() as per previous post because it gets overwritten later on. 

    However, the call to :

    dimensionDefaultingControllerHeader.parmAttributeValueSetDataSource(purchTable_ds, fieldStr(PurchTable, DefaultDimension));

    ... seems to setup a link between PurchTable and VendInvoiceInfoTable for the financial dimension.

    Doing a quick and dirty test I can manually set PurchTable.DefaultDimension after the call to super() within the call to active() on VendInvoiceInfoTable datasource (as per screenshot below).

    I did this because I've found that during the call to super() the value of the PurchTable.DefaultDimension appears to be finally set.

    This populates the Vendor invoice header's financial dimension form correctly and allows me to save the invoice.

    I would appreciate some more direction on where is the best place to customise this required behaviour.

    Thanks.

    VendEditInvoice-DataSources_2D00_VIIT_2D00_active.PNG

  • _MGP Profile Picture
    506 on at
    RE: Override Financial dimensions on Vendor invoice creation

    Hi Sukrut,

    Apologies on the confusion. When I refer to not compromising standard functionality I meant it in relation to the code that deals with event handling that I do not fully understand.

    Say I take the default dimension off the PurchTable, I would like to merge it with another dimension value (see my previous response to Ludwig which hopefully explains the context).

    I've been thinking about writing the new dimension value to the datasource object and maintaining the call to parmAttributeValueSetDataSource .

    Let me know if you need any more detail or clarification.

  • _MGP Profile Picture
    506 on at
    RE: Override Financial dimensions on Vendor invoice creation

    Hi Ludwig,

    This earlier post describes the scenario. The solution which has been proposed is to create a financial dimension named "SpecialBank" which is an attribute of the PO line. Say you have several PO's attached to a Vendor invoice. If any 1 PO line across all of these attached PO's has a "SpecialBank" attribute value of "Bank X" then we want to force the Vendor Invoice HEADER to inherit the same value for this dimension. The logic behind it is to allow a Payment run off only these invoices (with this tagged value) being paid via Bank X.

    I'm sorry but I'm not knowledgeable enough to know about the GL Parameters you have mentioned.

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Override Financial dimensions on Vendor invoice creation

    Hi,

    Why do you need to make this modification?

    Isn't the GL Parameter 'values used for summary account' sufficient?

    Best regards,

    Ludwig

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
KP-31070522-0 Profile Picture

KP-31070522-0 3

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans