Dynamics Search Engine

Wednesday, April 16, 2008

How to write a web lookup method in X++ (Dynamics Ax)

This article is for those who has basic knowledge of Dynamics Ax (Axapta).
To write this method I used Ax 3.0

Prerequisite: You should have Ax 3.0 Enterprise Portal (EP) installed and license for EP development.

1. Open your Ax application then AOT.

2. Create a new table and rename it as you wish (I used a name "WebLookUpTable") and add three fields to it as shown below:













3. Now go to Methods node of the table you just created and add a new method.

4. Rename the method "webLookUpTableTest" or as you wish. Your method now is a void type. Add "client static" before void key work.

5. Now add the following lines to your method.

client static void webLookUpTableTest()
{
webTableLookup webTableLookup;
Query query;
QueryBuildDataSource queryBuildDataSource;
;

webTableLookup = webTableLookup::newParameters(tableNum(WebLookUpTable));
webTableLookup.addLookupfield(fieldNum(WebLookUpTable, ProfileId),true);
webTableLookup.addLookupfield(fieldNum(WebLookUpTable, Name));
webTableLookup.addLookupfield(fieldNum(WebLookUpTable, Phone));
query = new Query();

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

webTableLookup.parmQuery(query);
webTableLookup.run();

}

5. Browse your newly created table and create some data in the table.

6. Now your table and web lookup method is ready. You can use it on your existing web form or create a new web form to test it. I used a new web form.

7. To create a new web form go to Web node of AOT then Web Forms. Right click on Web Forms node, on context menu click on New Web Form. Give a name to this form if you wish. Add a WebEdit control to the web form. Go to the Methods node of the WebEdit control and select then right click on it and select Override Methods then "lookup" method.

8. Double click on the lookup method and add "WebLookUpTable::webLookUpTableTest();" after super().

Your web form will look like:













9. Right click on the WebEdit control and click on Properties. Set "Custom" for LookupMethod property.

10. Create a menu item for this web form and add it to a web menus wherever you want. I added it to EPSalesHome->Common tasks->Lookup test.















11. Save your entire customization and run your EP. Browse the web form you added and see the control on that form. A lookup button will be available on this control.



[control on web form]







[Lookup form]











In the above lookup method, you are using "webTableLookup" class to crate lookup. The Query and QueryBuildDataSource have been used to set data data source to web lookup form.

webTableLookup.addLookupfield(fieldNum(WebLookUpTable, ProfileId),true);

In the above line true has been passed because of return value. It means the selected ProfileId to be returned to the WebEdit control.


No comments:

Post a Comment