Custom lookup in AX 2012

Dear Friends,

Today, in this post we are going to share how you can add custom lookup in your form control in AX 2012.

Let's start...

1) In the AOT, expand Forms, expand the form, expand Designs, right-click Design. Add or drag a new control in the design section of form.

Example: You can drag a string field from your form data source.

2) Expand the control on which you want to add the custom lookup, right-click Methods, click Override method, and then click lookup. The lookup method opens in the code editor.


3) Copy paste the below code.

public void lookup()
{
    Query query = new Query();
    QueryBuildDataSource queryBuildDataSource;
    QueryBuildRange queryBuildRange;
 
    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(custTable), this);
 
    sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
    sysTableLookup.addLookupField(fieldNum(CustTable, CustGroup));
 
    queryBuildDataSource = query.addDataSource(tableNum(CustTable));
 
    queryBuildRange = queryBuildDataSource.addRange(fieldNum(CustTable, CustGroup));
    queryBuildRange.value('40');
 
    sysTableLookup.parmQuery(query);
 
    sysTableLookup.performFormLookup();
 
    //super();
}

Note: When you override the lookup method, comment out the call to super. If you do not comment out the call to super, the standard lookup form might appear.

4) Open the form and check for custom lookup in that.

Note: For more information on this article click here.

We hope this solution helped you to add custom lookup on form control using X++ in AX 2012. Please comment your valuable feedback for this article...

Author:
Chirag Gupta
Microsoft Dynamics D365/AX 2012
Senior Technical Consultant at IBM Bangalore

Date:
4-Apr-2020

Happy Learning !!

Comments

Popular posts from this blog

[Solved] : Error: String or binary data would be truncated. Cannot execute a data definition language command on Vendor (VendLedgerReconciliationTmp)

AX 2012 - Command prompt compilation / AxBuild.exe for Parallel Compile on AOS of X++ to P-code / Parallel Compilation

AX 2012 - How to send SSRS report in email as an attachment using X++

AX 2012 - How to stop AOS when services got stuck at stopping status

AX 2012 - How to make a form field mandatory

Error: There was no endpoint listening at net.tcp://your_server_name:8201/Dynamics AX/Services…

Fetch vendor address using X++ in AX 2012

AX 2012 - How to print current date and time on SSRS Report

[Error] - Error in unit of amount in currency KES. Must be rounded to 0.01 | The unit of 37.563.5343100000000000 KES being posted to account 32710001-- is outside the current penny rounding threshold | Posting has been canceled

[Solved] : AX 2012 - No connection could be made because the target machine actively refused it 192.168.10.249:8201