Wednesday, April 15, 2015

Types Of Lookup In Ax 2012

EDT Lookup

First we need to create table
VetSpeciesTable
1) SpeciesID
2) Name
second we need to create primary index for speciesID , so set allow duplicate vale as No
third we need to set Primary index as speciesid

Create EDT for the Species and set the referencetable. for clear idea , i ill show the below screen shot.





once we have complete the procedure, if we use the above edt speciesID to any  table automatically foreignkey relation will create to current table.we ill get lookup of the table.



Create lookup in form without creating a method from table

Standard Example of code

Lookup in queries

\Forms\DirPartyQuickCreateForm\Data Sources\LogisticsPostalAddress\Fields\CountryRegionId\Methods\lookup


Output of the above code

AR-- All Customers-- Create customers


Creating Custom Lookup Dynamically by using Queries


VendTable we ill write one lookup method to display the additional with the existing lookup.

now we are going to write one lookup method and after that we are going to call this method in form.


Code
public void lookupVendorByCurrency(FormControl _formControl, Currencycode _currency)
{
    Query               query;
    QueryBuildDataSource qbds;
    QueryBuildRange      qbr;
    SysTableLookup      sysTableLookup;

    query = new Query();
    sysTableLookup = SysTableLookup::newParameters(tableNum(VendTable), _formControl,true);
    query.addDataSource(tableNum(VendTable));
    qbr = qbds.addRange(fieldNum(VendTable,Currency));
    qbr.value(queryValue(_currency));
    sysTableLookup.addLookupfield(fieldNum(VendTable,AccountNum),true);
    sysTableLookup.addLookupfield(fieldNum(VendTable,Party));
    sysTableLookup.addLookupfield(fieldNum(VendTable,Currency));
 

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

Go to the Cust table form and click datasource custtable and field vendaccount .create lookup method for thgat field

public void lookup(FormControl _formControl, str _filterStr)
{
    VendTable::lookupVendorByCurrency(_formControl,CustTable.Currency);
}



Output

AR-- All customers--edit button-- Miscellaqneous Details group--vendor account filed

Previously it used to disaplay vendaccount and name.. now we added the currency field in the existing lookup.




Lookup by args

Standard Form Name :AssetDepBookLVPTransferProposal(\Forms\AssetDepBookLVPTransferProposal\Designs\DesignList\TransferToAssetId\Methods\lookup)

Table:Assettable(lookupAccountNumLVP Method)

No comments: