Thursday, October 29, 2015

AX 2012:Lookup method

Lookup 

public void lookup() //For single table //Write in Form Level Design>Field>Lookup
{

// create the query for the lookup

Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;

/// Intantiantes a SysTableLookup object telling it which control activated the lookup, and
// what table should be displayed inside the lookup form.(root table)

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(LTCustomerDetails), this);

// Add fields that will be shown in the lookup as columns
sysTableLookup.addLookupField(fieldNum(LTCustomerDetails, LTCustomerID));
sysTableLookup.addLookupField(fieldNum(LTCustomerDetails, LTCustomerName));

queryBuildDataSource = query.addDataSource(tableNum(LTCustomerDetails));
queryBuildRange = queryBuildDataSource.addRange(fieldNum(LTCustomerDetails, LTCustomerID));
queryBuildRange.value('1');

//Add the query to the lookup form
//Passes the query to the sysTableLookup.

sysTableLookup.parmQuery(query);

// Perform the lookup

sysTableLookup.performFormLookup();

}


//to call the lookup if its witten in table level

public client static void lookupcustomer(FormStringControl  _ctrl) //For single table new method //on table level
{
SysTableLookup sysTableLookup =          SysTableLookup::newParameters(tableNum(LTDuserTable), _ctrl);
//rest is same as above code
}
public void lookup() //then call that method on form level
{
LTPurchaseDetails::lookupcustomer(this);
}

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8