Wednesday, 12 December 2018

D365 OnLookup form method event handler

[FormControlEventHandler(formControlStr(PurchAgreement, PurchAgreementHeader_ParentPurchAgreement), FormControlEventType::Lookup)]
     public static void PurchAgreementHeader_ParentPurchAgreement_OnLookup(FormControl sender, FormControlEventArgs e)
     {
  
        SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tablenum(PurchAgreementHeader), sender);
        FormRun                 element = sender.formRun();
        FormDataSource          purchAgreementHeader_ds;
        Query                   q   = new Query();
        QueryBuildDataSource    qbds;
        QueryBuildRange         qbr;
        PurchAgreementHeader    parentPurchAgreementHeader;

        purchAgreementHeader_ds = element.dataSource(formDataSourceStr(PurchAgreement, PurchAgreementHeader)) as FormDataSource;

        parentPurchAgreementHeader = purchAgreementHeader_ds.cursor();
        qbds   = q.addDataSource(tableNum(PurchAgreementHeader));
        qbr    = qbds.addRange(fieldNum(PurchAgreementHeader,VendAccount));
        qbr.value(parentPurchAgreementHeader.VendAccount);
        sysTableLookup.addLookupfield(fieldnum(PurchAgreementHeader, PurchNumberSequence), true);
        sysTableLookup.parmQuery(q);
        sysTableLookup.performFormLookup();

        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
        ce.CancelSuperCall();
    }

No comments:

Post a Comment