Create a custom lookup for the purchase agreement of the vendor selected

 Today we have a requirement to create a a custom look up for the purchase agreement for the vendor which is selected


1) Create a custom lookup on the table level 

2) Call on the form 


1) create a custom lookup for the purchase agreement  


/// <summary>

    /// look up for Purchase Agreement against the vendor

    /// </summary>

    static void ihslookupVendPurchaseAgreement(FormStringControl _callingControl, VendAccount _vendAccount)

    {

        Query                   query = new Query();

        QueryBuildDataSource    queryBuildDataSource;

        QueryBuildRange         qbrVendAccount, qbrAgreementState, qbrBuyingLegalEntity;

        VendAccount             vendAccount;

        PurchAgreementHeader    purchAgreementHeader;

        CompanyInfo             companyInfo =    CompanyInfo::findByCompany_IN(curExt());


        select purchAgreementHeader

            where purchAgreementHeader.VendAccount == _vendAccount

                && purchAgreementHeader.BuyingLegalEntity == companyInfo.RecId;


        SysTableLookup          sysTableLookup = sysTableLookup::newParameters(tableNum(PurchAgreementHeader), _callingControl);

    

        sysTableLookup.addLookupField(fieldNum(PurchAgreementHeader, PurchNumberSequence));

        sysTableLookup.addLookupfield(fieldNum(PurchAgreementHeader, DocumentTitle));

        sysTableLookup.addLookupField(fieldNum(PurchAgreementHeader, VendAccount));

        sysTableLookup.addLookupMethod(tableMethodStr(PurchAgreementHeader, vendName));

        sysTableLookup.addLookupField(fieldNum(PurchAgreementHeader, AgreementState));


        queryBuildDataSource = query.addDataSource(tableNum(PurchAgreementHeader));


        qbrVendAccount = queryBuildDataSource.addRange(fieldNum(PurchAgreementHeader, VendAccount));

        qbrVendAccount.value(_vendAccount);


        qbrAgreementState = queryBuildDataSource.addRange(fieldNum(PurchAgreementHeader, AgreementState));

        qbrAgreementState.value(enum2Str(AgreementState::Effective));


        qbrBuyingLegalEntity = queryBuildDataSource.addRange(fieldNum(PurchAgreementHeader, BuyingLegalEntity));

        qbrBuyingLegalEntity.value(int642Str(companyInfo.RecId));


        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();

    }


======================================================================


Call the above method on form control level


[ExtensionOf(formControlStr(EntAssetWorkOrderTable, IHSEWasteManagementGroup_PurchAgreement))]

Final class IHSEntAssetWorkOrderTableFrm_EWastePurchAgreementCtrl_Extension

{

    public void lookup()

    {

        FormStringControl    eWasteManagement_fsc   = any2Object(this) as FormStringControl;

        FormDataSource       eWasteManagement_ds = eWasteManagement_fsc.formRun().dataSource(tableStr(IHSEWasteManagement));

        IHSEWasteManagement  eWasteManagement = eWasteManagement_ds.cursor();


        next lookup();

     

        IHSEWasteManagement::ihslookupVendPurchaseAgreement(this, eWasteManagement.VendAccountNum);

    }


}

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++