Saturday 15 April 2017

Lookups in Dynamics 365 or AX7

Lookups are almost same as AX 2012 but need to write in extension class. Need to copy the event handler and paste in Class and write the same logic as AX 2012.

https://ranjithdax.blogspot.in/2015/01/creation-of-sys-look-in-microsoft.html (AX 2012)

Will get different lookup scenarios one of the scenario is
Scenario: How to filter lookup based on one field value in Dynamics 365.

So 1st  need to get the value of the field value to pass as a range, for that need to get the control value from FORM.

The below code is used to get the filtered lookup based on the other field value.



  [FormControlEventHandler(formControlStr(RetailLoyaltyCards, RetailLoyaltyCard_AuthorizedUser), FormControlEventType::Lookup)]
    public static void RetailLoyaltyCard_AuthorizedUser_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(DirPartyPostalAddressView), sender);
        QueryBuildDataSource            queryBuildDataSource;
        Query                           query;
        FormRun                         formRun;
        FormControl                     formCtrl;
       
        formRun = sender.formRun();

        formCtrl = formRun.design().controlName(formControlStr(RetailLoyaltyCards, RetailLoyaltyCard_Party2));

        sysTableLookup.addLookupfield(fieldNum(DirPartyPostalAddressView, LocationName), true);
        query = new Query();
        queryBuildDataSource = query.addDataSource(tableNum(DirPartyPostalAddressView));
        queryBuildDataSource.addRange(fieldNum(DirPartyPostalAddressView, Party)).value(SysQuery::value(str2Int64(formCtrl.valueStr())));
          
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }




No comments:

Post a Comment