Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet

Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Friday, March 10, 2006

Replacing the default lookup form

Have you ever wanted to replace the default lookup form, for say items on a Purchase Order? Well when developing customization and getting AX to fit the business need of a client, sometimes it's very helpful to do just that.

Here I want to walk you through the basic steps of creating a new form, and using it as the lookup form for Items on a Purchase Order.

In our pretend requirement here, the company wants to make only those items that are associated to the given selected Vendor available for selection. Also, they want to be able to search the items list based on the Vendor Item number and description.

The solution to do this is (1) create a form that has the CustVendExternalItem as it's data source. (2) Setup the newly created form, change its methods, and make the CustVendExternalItem.ItemId field as the element.selectMode() value. (3) Take and override at the Form control, ItemId field, lookup() method. (4) Take and pass in the Vendor Account as part of the Parms so that the form can be filtered to show on those items related to the given Vendor Account.

I am going to assume that everyone reading this knows how to create a new form, and set the CustVendExternalItem table as a data source for the form. The next thing you want to do is open the methods of the form and add VendAccount variable for use in the filter.
Next override the init() method and add similar code like this:
VendAccount = element.args().parm()
Make sure to add the above code Befor the super(); call. Now an important step here is to call the element.selectMode(CustVendExternalItem_ItemId). This set the ItemId field as the given selection on form close. Important note here is that if you have not auto declare the field then it will not compile.
Now override the run() method of the class, and after the super(); call perform a CustVendExternalItem_ds.filter() method where you will use the VendAccount variable as the data to filter on. The field to filter on here is the CustVendRelation field. After that make add the following method calls:

The above should be compiled, and is now ready to be set as the lookup form. Next we want to move to the Itemid field on the Line Grid for the Purchase Order form. We want to here, override the lookup() method. From within this method you want to do something similar to this:

Args args = new Args();
FormRun itemLookUp;

itemLookUp = new FormRun(args);

The above code will then launch the new form as the lookup form. Now you have given a form that is filtered by the Vendor account. This form also allows for searching based on the Vendor item number and description.

To take this further code could be added that would check the ItemId field to make sure that an item it truly only associated with a given Vendor account. Also you can do a lot with the lookup form itself, by adding tabs, and different “types” of the ItemId look ups based on the business process and need.

Hopefully this will get you started on replacing the lookup forms, and hopefully you can see what a great benefit this can be. Look here for future code examples, 4.0 details, and my review of the book by Scott Hamilton.

Find a job at: www.DynamicsAXJobs.com


Anonymous Dan said...

Good overview for when a complex lookup is required. If it's something simpler (like your example), you can still override 'lookup' on the datasource field or control, but instead of creating an entirely new form just create an instance of SysTableLookup. This allows you to add specific fields and define a query with extra ranges/joins etc. If you need a more complicated lookup form (eg locations or anything hierarchy based), then a whole new form is the way to go. In your example, you could have also defined a new EDT that derives from ItemID called PurchItemID, then set the 'FormHelp' property to the name of your form. This would then apply automatically on all forms using PurchLine.

9:07 AM  

Post a Comment

Links to this post:

Create a Link

<< Home

Copyright 2005-2011, J. Brandon George - All rights Reserved