Implement lookup through event handler

 If you want to write a lookup through the event handler. Follow the following code;


[FormControlEventHandler(formControlStr(SalesTable, SalesLine_CostSheetId), FormControlEventType::Lookup)]

    public static void SalesLine_CostSheetId_OnLookup(FormControl sender, FormControlEventArgs e)

    {

        Query                                   query;

        QueryBuildDataSource                    qbdsFabCostSheetsCalculation;

        QueryBuildRange                         queryBuildRange;

        SysTableLookup                          sysTableLookup;

        FormControlCancelableSuperEventArgs     formControlCancelSuper;         

        query = new Query();         

        formControlCancelSuper = e as FormControlCancelableSuperEventArgs;         

        formControlCancelSuper.CancelSuperCall();         

        sysTableLookup = SysTableLookup::newParameters(tableNum(FabCostSheetsCalculation), sender);

        sysTableLookup.addLookupField(fieldNum(FabCostSheetsCalculation, CostSheetId));

        

        qbdsFabCostSheetsCalculation = query.addDataSource(tableNum(FabCostSheetsCalculation));


        qbdsFabCostSheetsCalculation.addRange(fieldNum(FabCostSheetsCalculation,Status)).value(queryValue(FabCostWorkflowStatus::Approved));

        

        FormDataSource salesLine_ds = sender.formRun().dataSource("SalesLine");

        SalesLine salesLine = salesLine_ds.cursor();


        qbdsFabCostSheetsCalculation.addRange(fieldNum(FabCostSheetsCalculation,ArticleId)).value(queryValue(salesLine.ItemId));

       

        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();         formControlCancelSuper.CancelSuperCall();

    }


Thanks.



Comments

Popular posts from this blog

Create custom workflow in D365 X++

Convert amount from one currency to another currency using X++

How to Create Extended Data Types (EDTs) in Finance and Operations of Dynamics 365 -- F&O Customization Part 2