Skip to main content

Expression Builder Lookup using X++

I was just wondering if there is any way of popping a lookup form during the program execution.
We have seen many ways of creating lookups – EDT’s, relations, AutoLookup and through custom code [SysTableLookup]
Let us consider an example: I have a select query whose behaviour should be dynamic based on the User input. We might have used query Framework classes many a times to do this.
I was just going through the standard classes and found this code useful with minimum tweaking of code.
Try out the below example: This example will help you to select the custAccount and based on the selected customer account it brings you the last invoiced sales order.
Note: The columns in the form are built runtime using the AutoLookup fields.
static void SR_expressionBuilderLookUp(Args _args)
{
CustTable custTable;
ExtendedDataTypeName extendedDataType = extendedtypestr(custAccount);
CustAccount custAccount;

Object expressionBuilderLookup;
Args args = new Args(formstr(SysExpressionBuilderLookup));
;
expressionBuilderLookup = new FormRun(args);
expressionBuilderLookup.parmExtendedDataType(extendedDataType);
expressionBuilderLookup.init();
expressionBuilderLookup.run();
expressionBuilderLookup.wait();
custAccount = expressionBuilderLookup.parmSelectedValue();
if(custAccount)
{
info(strfmt(‘Last SO of customer %1 is %2′, custAccount, CustTable::find(custAccount).lastInvoice().SalesId));
}
}

Below is the lookup image for your reference

Popular posts from this blog

Passing values between form and class

Class name is EmplDuplication and Form is EmplTable . void clicked() {    MenuFunction mf;    args args = new Args();    ;     args.record(EmplTable);     mf = new menufunction(identifierstr(EmplDuplication), MenuItemType::Action); mf.run(args); } Meanwhile, in the main() method of the EmplDuplication class, we need to put this Axapta x++ code to get the datasource: static void main(Args args) {     EmplDuplication EmplDuplication; EmplTable localEmplTable; ;     if(args.record().TableId == tablenum(EmplTable)) localEmplTable = args.record();     ... }

What does this mean: "The form datasource query object does not support changing its AllowCrossCompany property after the form has executed the query."?

I have made a form with datasources vendtable and vendtrans. Inside vendtable_ds.executequery() looks like this: QueryBuildDataSource queryBuildDatasource ,queryBDS_VendTrans_Invoice; ; queryBuildDatasource = this.query().dataSourceTable(tablenum(vendtable)); queryBDS_VendTrans_Invoice = this.query().dataSourceTable(tablenum(vendtrans)); if (curext() == "MASTERCOMP") { this.query().allowCrossCompany(true); } else { this.query().allowCrossCompany(false); } //FilterVendorName = stringedit control on form if (FilterVendorName.text()) { queryBuildDatasource.addRange(fieldNum(VendTable,Name)).value(strfmt("*%1*", FilterVendorName.text())); } else { queryBuildDatasource.clearRange(fieldNum(VendTable,Name)); } //FilterInvoiceNumber = stringedit control on form if (FilterInvoiceNumber.valueStr() == "") { queryBDS_VendTrans_Invoice.enabled(false); } else { queryBDS_VendTrans_Invoice.enabled(true); queryBDS_VendTrans_In...