programming4us
programming4us
ENTERPRISE

Microsoft Dynamics AX 2009 : Building Lookups - Using a form for lookup building

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
9/25/2012 1:47:43 AM
In numerous situations, standard, automatic, or even dynamic runtime lookups cannot display the required data. For example, it might be a lookup with tab pages or a search field. In such cases, Dynamics AX offers the possibility to create an AOT form and use it as lookup.

In this recipe, we will demonstrate how to create a lookup using an AOT form. As an example, we will modify the standard customer account lookup to display only active customers.

How to do it...

  1. 1. In AOT, create a new form called CustLookup. Add a new data source with the following properties:

    Property Value
    Name CustTable
    Table CustTable
    AllowCreate No
    AllowEdit No
    AllowDelete No
    AllowCheck No
    OnlyFetchActive Yes
    Index AccountIdx

  1. 2. Change the form's following design properties:

    Property Value
    Frame Border
    WindowType Popup

  1. 3. Add a new Grid to the form's design:

    Property Value
    Name Customers
    ShowRowLabels No
    DataSource CustTable

  2. 4. Add a new StringEdit control to the grid:

    Property Value
    Name AccountNum
    DataSource CustTable
    DataField AccountNum
    AutoDeclaration Yes

  1. 5. Add another StringEdit control to the grid, right after AccountNum:

    Property Value
    Name Name
    DataSource CustTable
    DataField Name

  1. 6. Add one more StringEdit control to the grid, right after Name:

    Property Value
    Name Phone
    DataSource CustTable
    DataField Phone

  1. 7. Add a new ComboBox control to the end of the grid:

    Property Value
    Name Blocked
    DataSource CustTable
    DataField Blocked

  1. 8. Override the form's init() method with the following code:

    public void init()
    
    {;
    super();
    element.selectMode(AccountNum);
    }
    
  2. 9. Override the form's run() with the following code:

    public void run()
    
    {
    FormStringControl callingControl;
    boolean filterLookup;
    ;
    callingControl = SysTableLookup::getCallerStringControl(
    element.args());
    filterLookup = SysTableLookup::filterLookupPreRun(
    callingControl,
    AccountNum,
    CustTable_ds);
    super();
    SysTableLookup::filterLookupPostRun(
    filterLookup,
    callingControl.text(),
    AccountNum,
    CustTable_ds);
    }
    
  3. 10. Finally, override init() of the CustTable data source with the following code:

    public void init()
    
    {
    Query query;
    QueryBuildDataSource qbds;
    QueryBuildRange qbr;
    ;
    query = new Query();
    qbds = query.addDataSource(tablenum(CustTable));
    qbr = qbds.addRange(fieldnum(CustTable, Blocked));
    qbr.value(queryvalue(CustVendorBlocked::No));
    this.query(query);
    }
    
  4. 11. The form in AOT should look like this:

  1. 12. Locate the extended data type CustAccount in AOT, and change its property:

    Property Value
    FormHelp CustLookup

  1. 13. To test the results, open Accounts receivable | Sales Order Details and start creating a new sales order. Notice that now Customer account lookup is different, and it includes only active customers:

How it works...

The newly created CurrencyLookup form will replace the automatically generated customer account lookup. It is recommended to append text Lookup to the end of the form name, so that lookups can be easily distinguished from other AOT forms.

In order to make our form lookup looks exactly like a standard lookup, we have to adjust its layout. So, we set form design Frame and WindowType properties respectively to Border and Popup. This removes form borders and makes the form lookup like a true lookup. By setting the grid property ShowRowLabels to No, we hide grid row labels, which are also not a part of automatically generated lookups. Then, we create a grid with four controls, which are bound to the relevant CustTable table fields.

Next, we change the data source properties. We do not allow any data change by setting AllowEdit, AllowCreate, and AllowDelete properties to No. Security checks should be disabled by setting AllowCheck to No. To increase performance, we set OnlyFetchActive to Yes, which will reduce the size of the database result set to only the fields that are visible. We also set the data source index to improve lookup performance.

Now, we need to define which form control will be returned as a lookup value to the calling form upon user selection. We need to specify it manually in the form's init() by calling element.selectMode() with the name of the AccountNum control as argument.

In the form's run(), we simulate standard lookup filtering, which allows user to user * symbol to search for records in the lookup. For example, if the user types 1* into the Customer account control, the lookup will open automatically with all customer accounts starting with 1. To achieve that, we use the filterLookupPreRun() and filterLookupPostRun() methods of the standard SysTableLookup class. Both methods requires calling a control, which we get by using getCallerStringControl() method of SysTableLookup. The first method reads user input and returns true if a search is being performed, otherwise, false. It must be called before the super() in the form's run() and accepts four arguments:

  1. 1. The calling control on the parent form.

  2. 2. The returning control on the lookup form.

  3. 3. The lookup data source.

  4. 4. An optional list of other lookup data sources.

The filterLookupPostRun() must be called after the super() in the form's run() and also accepts four arguments:

  1. 1. A result value from previously called filterLookupPreRun().

  2. 2. The user text specified in the calling control.

  3. 3. The returning control on the lookup form.

  4. 4. The lookup data source.

The code in the CustTable data source's init() replaces the data source query created by its super() with the custom one. Basically, here we create a new Query object, add a range to show only active customers, and set this object as the new CustTable data source query. This ensures that there are no dynamic links from the caller form's data source.

The value CustLookup in the FormHelp property of the CustAccount extended data type will make sure that this form is opened every time the user opens Customer account lookup.

See also

Processing Data, Building a query object

Other  
  •  The HP Virtual Server Environment at a Glance : Overview of the HP Virtual Server Environment
  •  The HP Virtual Server Environment at a Glance : The Target Problem—Rampant System Over-Provisioning
  •  Oracle Coherence 3.5 : Clustered cache topologies (part 3) - Near cache
  •  Oracle Coherence 3.5 : Clustered cache topologies (part 2) - Partitioned Cache service
  •  Oracle Coherence 3.5 : Clustered cache topologies (part 1) - Replicated Cache service
  •  Oracle Coherence 3.5 : Planning Your Caches - Anatomy of a clustered cache
  •  Memory Management : Clean Up Managed Resources Using the Dispose Pattern
  •  Memory Management : Get the OS View of Your Application's Memory, Clean Up Unmanaged Resources Using Finalization
  •  Active Directory Domain Services 2008 : Create a WMI Filter, Import a WMI Filter, Export a WMI Filter
  •  Active Directory Domain Services 2008 : Filter Group Policy Object Scope by Using Security Groups, Disable User Settings in a Group Policy Object, Disable Computer Settings in a Group Policy Object
  •  
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    programming4us programming4us
    programming4us
     
     
    programming4us