Saturday 22 April 2017

Display or edit methods in Dynamics 365 or AX7

New Display or Edit method need to write in extension class.

In the below code is the example for display method in CustTable extension.

[ExtensionOf(tablestr(CustTable))]
final class CustTableEventHandlers_Extension
{
    [SysClientCacheDataMethodAttribute(true)]
    display RetailLoyaltyCardNumber primaryLoyaltyNumber()
    {
        RetailLoyaltyCard   retailLoyaltyCard;

        select firstonly CardNumber from retailLoyaltyCard
            where retailLoyaltyCard.Party == this.party
                && retailLoyaltyCard.Primary == NoYes::Yes;

        return retailLoyaltyCard.CardNumber;
    }
}

After writing logic we need to assign this method to the control in Form.

Set control properties "data method" in the below format

ExtensionClassName::MethodName



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();
    }