Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Dialog field custom lo...
Finance forum
Answered

Dialog field custom lookup on form datasource extension throwing exception

Posted on by 2,650
Hi All,
 
I have developed an extension for the SalesTable form relating to the SalesLine formdatasource.
 
 
Inside this extension I have extended the ValidateDelete method to include a custom dialog where the user must enter some values which will be written into a different table.
 
 
Everything is working ok until I try to override one of the dialog fields to use a custom lookup method.
 
[ExtensionOf(FormDataSourceStr(SalesTable, SalesLine))]
internal final class TSTSalesTableFormSalesLineDs_Extension
{
    /// <summary>
    /// Lookup for deleted sales line reason codes
    /// </summary>
    /// <param name = /_control/>Dialog control</param>
    private void reasonCodeLookup(FormStringControl    _control)
    {
        SysTableLookup          sysTableLookup;
        QueryBuildDataSource    queryBuildDataSource;
        Query                   query = new Query();
        queryBuildDataSource = query.addDataSource(tablenum(TSTSalesLineReasonTable));
        sysTableLookup = SysTableLookup::newParameters(tablenum(TSTSalesLineReasonTable), _control);
        sysTableLookup.addLookupfield(fieldnum(TSTSalesLineReasonTable, TSTSalesCode),  true);
        sysTableLookup.addLookupfield(fieldnum(TSTSalesLineReasonTable, TSTSalesCodeDesc));
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }
}
 
The code I am calling from my override is below which calls the custom lookup above - BOTH METHODS ARE IN THE SAME EXTENSION CLASS of the SalesLine form datasource in SalesTable form.
  
 deleteReasonCodeDlg = deleteDlg.addField(extendedTypeStr(TSTSalesCode));
           
 deleteReasonCodeDlg .registerOverrideMethod(methodStr(FormStringControl, lookup),
                methodStr(TSTSalesTableFormSalesLineDs_Extension, reasonCodeLookup),this);
 
The problem when I click on the dialog field when the dialog loads is I get an exception telling me the FormDataSource object doesn't contain the method reasonCodeLookup - but it should as I have added it in the extension of the formDatasource class as above?
 
 
 
 
 
 
What is the best way to accomplish this to ensure the override lookup is called on the dialog in this scenario?
  • Verified answer
    Kauto Profile Picture
    Kauto 2,650 on at
    Dialog field custom lookup on form datasource extension throwing exception
    I have found a solution myself.
     
    I just created a new class which handled the dialog, custom lookup and return of the collected data.
     
    I then called this class from within my salesLine datasource form code extension and it is working well.
     
    It doesn't look like it is possible to instantiate a dialog class on a form datasource extension and include a custom lookup within the same extension class. 
  • Kauto Profile Picture
    Kauto 2,650 on at
    Dialog field custom lookup on form datasource extension throwing exception
    Hi Layan
     
    So what you are saying is the lookup method should exist in an extension of the SalesTable form's INIT method.
     
    Then I am able to call the registerOverrideMethod to reference it for custom lookup through my other extension which is an extension of the SalesLine data source on the same form?

    You have to understand that I am creating a dialog via the extension so if I create a new extension for the SalesTable form INIT method - I can't reference the dialog field in that code because it won't exist.

    So again - I don't think the below solution will work? I have attempted it and stopped because I know the dialog field won't be able to be found in the INIT method extension because it only gets created in the ValidateDelete extension method
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 6,882 Super User 2024 Season 2 on at
    Dialog field custom lookup on form datasource extension throwing exception
    Hi Kauto,
     
    When we use registerOverrideMethod we do it on form level, where we call the registerOverrideMethod inside the init method.
     
    Please check this link to see how to do it
     
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,135 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans