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

Dynamics Axapta: Sales Orders & Business Connector

Well, again folllowing my same idea of writting close to nothing and pasting code, I'll paste in some code to create a sales order from some basic data and the invoice it. I'll try to explain more in the future. AxaptaObject axSalesTable = ax.CreateAxaptaObject("AxSalesTable"); AxaptaRecord rcInventDim = ax.CreateAxaptaRecord("InventDim"); AxaptaRecord rcCustTable = ax.CreateAxaptaRecord("CustTable"); rcCustTable.ExecuteStmt("select * from %1 where %1.AccountNum == '" + MySalesOrderObject.CustAccount + "'"); if (MySalesOrderObject.CurrencyCode.Trim().Length == 0) MySalesOrderObject.CurrencyCode = rcCustTable.get_Field("Currency").ToString().Trim(); string sTaxGroup = rcCustTable.get_Field("taxgroup").ToString().Trim(); //set header level fields axSalesTable.Call("parmSalesName", MySalesOrderObject.SalesName.Trim()); axSalesTable.Call("parmCustAccount", M

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