Friday, June 2, 2023

A dialog on form with the customer lookup for a specific financial dimension in D365 FinOps

 Recently I had a request to create a custom form in Dynamics 365 Finance and Operations. One requirement was that prior to the form opening, it would prompt the user for a date (defaulted in with the current date) and a value from a specific financial dimension. The working prompt form would look like this (with the custom lookup code on the financial dimension)

So, here's how I would create a custom dialog on a form with a customer lookup for a specific financial dimension in D365 FinOps. The dialog code itself is not hard to do. It simply is placed in the init() method of the main form

    public void init()
    {
        super();

        // build the dialog for prompt
        Dialog dialog = new Dialog("Label goes here",element);
        DialogField dfDate = dialog.addField('Date1980','Date');
        dfDate.value(DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()));

        DialogField dfDimValue = dialog.addField('DimensionValue','LocationSite');
        FormBuildStringControl control;
        control = dfDimValue.control();

        // use the custom lookup
        control.registerOverrideMethod('LookUp','dimLookup',this);

        // if we click OK, we run, otherwise, close the form
        if (dialog.run())
        {
            dlDate = dfDate.value();
            dlDimValue = dfDimValue.value();

            boolean dlClosed = dialog.closedOk();

            if (dlClosed)
            {

		   // code does in here
            }
        }
        else
        {
            element.close();
        }

    }

This key line in the code above is the following:

control.registerOverrideMethod('LookUp','dimLookup',this);


This line allows us to override the lookup method of the control in the dialog, and replace it with our custom code.  This method exists on the form as well.

    private void dimLookup(FormStringControl _control)
    {
        
        Query query = new Query();
        QueryBuildDataSource qbdsDimensionFinancialTag = query.addDataSource(tableNum(DimensionFinancialTag));
        QueryBuildRange qbrFinancialTagCategory = qbdsDimensionFinancialTag.addRange(fieldNum(DimensionFinancialTag, FinancialTagCategory));
        qbrFinancialTagCategory.value(strFmt('%1', DimensionAttribute::findByName(dimName, false).financialTagCategory()));

        SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(DimensionFinancialTag), _control,true);
        sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Value), true);
        sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Description));
        sysTableLookup.addSelectionField(fieldNum(DimensionFinancialTag, FinancialTagCategory));
        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();
    }

This is pretty standard lookup code using the SysTableLookup class.  That is all that is needed to accomplish my requirements (other than some specific requirement code that is not relevant here).

You can use this method to create any custom dialog form opening and have a customer lookup for any specific financial dimension in D365 Finance and Operations. If you have any more questions on how to do this yourself, please contact us.

No comments:

Post a Comment

D365 FinOps - How call a runnable class with URL parameters

We are already familiar with calling D365FO URL menu items or forms or Runnable class. To recap, I am giving few samples below To call  Disp...