Lookup method in AX7
[FormControlEventHandler(formControlStr(PurchTable, NCMR_OINCMRDispositionCodeId_011), FormControlEventType::Lookup)]
public static void NCMR_OINCMRDispositionCodeId_011_OnLookup(FormControl sender, FormControlEventArgs e)
{
FormRun formRun = sender.formRun();
FormStringControl NCMRDispositionCode = formRun.design(0).controlName("NCMR_OINCMRDispositionCodeId_011");
Query query = new Query();
QueryBuildDataSource qbds;
SysTableLookup sysTableLookup;
sysTableLookup = SysTableLookup::newParameters(tableNum(OINCMRDispositionCode), sender);
sysTableLookup.addLookupfield(fieldNum(OINCMRDispositionCode,NCMRDispositionCodeId));
sysTableLookup.addLookupfield(fieldNum(OINCMRDispositionCode, Description));
qbds = query.addDataSource(tableNum(OINCMRDispositionCode));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
Avoid Null Values in form lookup
public void lookup()
{
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildRange qbr;
SysTableLookup sysTableLookup;
super();
sysTableLookup = SysTableLookup::newParameters(tableNum(HcmPersonSkill), this);
sysTableLookup.addLookupfield(fieldNum(HcmPersonSkill,CertificationDescription));
sysTableLookup.addLookupfield(fieldNum(HcmPersonSkill, IsCertification));
qbds = query.addDataSource(tableNum(HcmPersonSkill));
qbds.addRange(fieldNum(HcmPersonSkill,CertificationDescription)).value(queryNotValue(strFmt(“%1″ ,”)));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
{
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildRange qbr;
SysTableLookup sysTableLookup;
super();
sysTableLookup = SysTableLookup::newParameters(tableNum(HcmPersonSkill), this);
sysTableLookup.addLookupfield(fieldNum(HcmPersonSkill,CertificationDescription));
sysTableLookup.addLookupfield(fieldNum(HcmPersonSkill, IsCertification));
qbds = query.addDataSource(tableNum(HcmPersonSkill));
qbds.addRange(fieldNum(HcmPersonSkill,CertificationDescription)).value(queryNotValue(strFmt(“%1″ ,”)));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
Lookup to use display method
public void lookup()
{
Query query = new Query();
QueryBuildDataSource invent,ecorestrans;
SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(EcoResProductTranslation), this);
ecorestrans = query.addDataSource(tableNum(EcoResProductTranslation));
sysTableLookup.parmQuery(query);
{
Query query = new Query();
QueryBuildDataSource invent,ecorestrans;
SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(EcoResProductTranslation), this);
ecorestrans = query.addDataSource(tableNum(EcoResProductTranslation));
sysTableLookup.parmQuery(query);
// Specify the fields to show in the form.
sysTableLookup.addLookupfield(fieldNum(EcoResProductTranslation, Name),true);
sysTableLookup.addLookupMethod("itemlookup");
sysTableLookup.addLookupfield(fieldNum(EcoResProductTranslation, Name),true);
sysTableLookup.addLookupMethod("itemlookup");
// Perform the lookup
sysTableLookup.performFormLookup();
}
sysTableLookup.performFormLookup();
}
display ItemId itemlookup()
{
InventTable InventTable;
select InventTable where InventTable.Product == this.Product;
return InventTable.ItemId;
}
{
InventTable InventTable;
select InventTable where InventTable.Product == this.Product;
return InventTable.ItemId;
}
Lookup for joining multiple tables
Lookup for reference field joining 2 tables :
If we have a field which is having relation with other tables ( reference field ),then when we go to datasource in form, go to the field RC >> override methods you get "lookupreference" and add below code
public Common lookupReference(FormReferenceControl _formReferenceControl)
{
Common ret;
Query q = new Query();
SysReferenceTableLookup lookup;
QueryBuildDataSource qdbs,qdbs1;
QueryBuildRange qbr;
lookup = SysReferenceTableLookup::newParameters(tableNum(MROParmFaultCause),_formReferenceControl,true);
qdbs = q.addDataSource(tableNum(MROParmFaultCause));
qdbs1 = qdbs.addDataSource(tableNum(MROFaultCauseRelation));
qdbs1.joinMode(JoinMode::ExistsJoin);
qdbs1.relations(true);
if(ObjectFaultSymptom.FaultType)
qdbs1.addRange(fieldNum( MROFaultCauseRelation,FaultType)).value(queryValue(ObjectFaultSymptom.FaultType));
if(ObjectFaultSymptom.FaultArea)
qdbs1.addRange(fieldNum( MROFaultCauseRelation,FaultArea)).value(queryValue(ObjectFaultSymptom.FaultArea));
qdbs1.addRange(fieldNum( MROFaultCauseRelation,FaultSymptom)).value(queryValue(ObjectFaultSymptom.FaultSymptom));
lookup.parmQuery(q);
lookup.addLookupfield(fieldNum(MROParmFaultCause,FaultCauseId));
lookup.addLookupfield(fieldNum(MROParmFaultCause,Description));
lookup.performFormLookup();
return lookup.performFormLookup() as Common;
{
Common ret;
Query q = new Query();
SysReferenceTableLookup lookup;
QueryBuildDataSource qdbs,qdbs1;
QueryBuildRange qbr;
lookup = SysReferenceTableLookup::newParameters(tableNum(MROParmFaultCause),_formReferenceControl,true);
qdbs = q.addDataSource(tableNum(MROParmFaultCause));
qdbs1 = qdbs.addDataSource(tableNum(MROFaultCauseRelation));
qdbs1.joinMode(JoinMode::ExistsJoin);
qdbs1.relations(true);
if(ObjectFaultSymptom.FaultType)
qdbs1.addRange(fieldNum( MROFaultCauseRelation,FaultType)).value(queryValue(ObjectFaultSymptom.FaultType));
if(ObjectFaultSymptom.FaultArea)
qdbs1.addRange(fieldNum( MROFaultCauseRelation,FaultArea)).value(queryValue(ObjectFaultSymptom.FaultArea));
qdbs1.addRange(fieldNum( MROFaultCauseRelation,FaultSymptom)).value(queryValue(ObjectFaultSymptom.FaultSymptom));
lookup.parmQuery(q);
lookup.addLookupfield(fieldNum(MROParmFaultCause,FaultCauseId));
lookup.addLookupfield(fieldNum(MROParmFaultCause,Description));
lookup.performFormLookup();
return lookup.performFormLookup() as Common;
}
=======================================================================
where projTable.Header==false
&& projTable.ProjGroupId== projGroup.ProjGroupId
&& projGroup.AllowCreateCourse==true
&& projTable.Type== ProjStatusTypeRule.ProjType
&& projTable.Status== ProjStatusTypeRule.ProjStatus
&& projStatusTypeRule.ProjStatusRule==ProjStatusRule::CreateCourse
{
info(strFmt("%1",projTable.ProjId));
}
--------------------------------------------------------------------------------------------------------------------
client static void lookupOpportunityId(FormStringControl
_callerControl, smmOpportunityId _opportunityId, DirPartyId _partyId)
{
Query query = new Query();
QueryBuildDataSource
queryBuildDataSource, queryBuildDataSource1;
SysTableLookup sysTableLookup =
SysTableLookup::newParameters(tablenum(smmOpportunityTable), _callerControl);
;
sysTableLookup.addLookupfield(fieldnum(smmOpportunityTable,
OpportunityId),true);
sysTableLookup.addLookupfield(fieldnum(smmOpportunityTable, Subject));
sysTableLookup.addLookupfield(fieldnum(smmOpportunityTable, PartyId));
sysTableLookup.addLookupfield(fieldnum(smmOpportunityTable,
ProbabilityId));
queryBuildDataSource =
query.addDataSource(tablenum(smmOpportunityTable));
queryBuildDataSource1 =
queryBuildDataSource.addDataSource(tablenum(smmQuotationProbabilityGroup));
// queryBuildDataSource1.relations(true);
queryBuildDataSource1.joinMode(JoinMode::ExistsJoin);
queryBuildDataSource.fetchMode(QueryFetchMode::One2One);
queryBuildDataSource1.addLink(fieldnum(smmOpportunityTable,
ProbabilityId), fieldnum(smmQuotationProbabilityGroup, ProbabilityId));
queryBuildDataSource1.addRange(fieldnum(smmQuotationProbabilityGroup, INU_smmProbabilityStatus)).value(queryvalue(INU_smmProbabilityStatus::Active));
queryBuildDataSource.addRange(fieldnum(smmOpportunityTable,
Status)).value(queryNotValue(smmOpportunityStatus::Won));
queryBuildDataSource =
queryBuildDataSource.addDataSource(tablenum(DirPartyTable));
queryBuildDataSource.joinMode(JoinMode::ExistsJoin);
queryBuildDataSource.fetchMode(QueryFetchMode::One2One);
queryBuildDataSource.addLink(fieldnum(smmOpportunityTable, PartyId),
fieldnum(DirPartyTable, PartyId));
queryBuildDataSource.addRange(fieldnum(DirPartyTable,
PartyId)).value(_partyId);
//INU_smmProbabilityStatus //BACK
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
Lookup for Field in form with Range :
public void lookup()
{
Query q = new Query();
QueryBuildDataSource qdbs;
SysTableLookup lookup = SysTableLookup::newParameters(tableNum(citStrapping),this,true);
qdbs = q.addDataSource(tableNum(citStrapping));
qdbs.addRange( fieldNum(citStrapping, Tank)).value(InventJournalTrans.citTank);
lookup.parmQuery(q);
lookup.addLookupfield(fieldNum(citStrapping, Feet),true);
lookup.addLookupfield(fieldNum(citStrapping, Tank));
lookup.performFormLookup();
{
Query q = new Query();
QueryBuildDataSource qdbs;
SysTableLookup lookup = SysTableLookup::newParameters(tableNum(citStrapping),this,true);
qdbs = q.addDataSource(tableNum(citStrapping));
qdbs.addRange( fieldNum(citStrapping, Tank)).value(InventJournalTrans.citTank);
lookup.parmQuery(q);
lookup.addLookupfield(fieldNum(citStrapping, Feet),true);
lookup.addLookupfield(fieldNum(citStrapping, Tank));
lookup.performFormLookup();
}
public void lookup()
{
Query q = new Query();
QueryBuildDataSource qdbs;
QueryBuildRange qbr;
SysTableLookup lookup = SysTableLookup::newParameters(tableNum(InventLocation),this);
lookup.addLookupfield(fieldNum(InventLocation,InventLocationId));
lookup.addLookupfield(fieldNum(InventLocation,Name));
qdbs = q.addDataSource(tableNum(InventLocation));
qbr = qdbs.addRange(fieldNum(InventLocation,InventSiteId));
qbr.value(InventJournalTable_FromInventSiteId.valueStr());
lookup.parmQuery(q);
lookup.performFormLookup();
}
Lookup for Field in form datasource with Range :
public void
lookup(FormControl _formControl, str
_filterStr)
{
Query q = new
Query();
QueryBuildDataSource qdbs;
QueryBuildRange qbr;
SysTableLookup lookup;
super(_formControl,
_filterStr);
lookup = SysTableLookup::newParameters(tableNum(InventLocation),_formControl);
lookup.addLookupfield(fieldNum(InventLocation,InventLocationId));
lookup.addLookupfield(fieldNum(InventLocation,Name));
lookup.addLookupfield(fieldNum(InventLocation,InventSiteId));
qdbs = q.addDataSource(tableNum(InventLocation));
qbr = qdbs.addRange(fieldNum(InventLocation,InventSiteId));
qbr.value(Storage_ToInventSiteId.valueStr());
lookup.parmQuery(q);
lookup.performFormLookup();
}
1. lookup with joinning 2 tables in Dynamic AX
public void lookup(){
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildDataSource QbdsJoin;
// Instantiate sysTableLookup object using table which will provide the visible fields
SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(TableName), this);
;
// Create the query.
qbds= query.addDataSource(tableNum(TableName));
qbds.addRange(fieldNum(TableName, FieldName)).value('Value');
//Join Table
QbdsJoin= qbds.addDataSource(tableNum(TableName2));
QbdsJoin.relations(true);
QbdsJoin.joinMode(JoinMode::ExistsJoin);
QbdsJoin.addRange(fieldNum(TableName2, Fieldname)).value('Value');
// Set the query to be used by the lookup form
sysTableLookup.parmQuery(query);
// Specify the fields to show in the form.
sysTableLookup.addLookupfield(fieldNum(TableName, FiledName));
sysTableLookup.addLookupfield(fieldId2Ext(fieldNum(TableName, Dimension), 1));
// Perform the lookup
sysTableLookup.performFormLookup();
}
2. addLookMethod() Structure in Dynamic AX:
sysTableLookup.addLookupMethod(tablemethodstr(CustTable,Name));
3. Looup For one table :
public void lookup()
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(custTable), this);
sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
sysTableLookup.addLookupMethod(tablemethodstr(CustTable,Name));
queryBuildDataSource = query.addDataSource(tableNum(CustTable));
queryBuildRange = queryBuildDataSource.addRange(fieldNum(CustTable, AccountNum));
queryBuildRange.value();
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
//super();
}
4. Multi Select Lookup :
On clicking the Ok button all the selected values are returned in the String control.
To get the values and RecId of the selected rows, simply override the modified method of the TestCtrl and add the below code.
public boolean modified()
{
boolean ret;
container c,v;
int i;
ret = super();
if (ret)
{
c = msCtrl.get(); // get RecIds of the selected rows
v = msCtrl.getSelectedFieldValues(); // get actual value of the selected rows
for (i = 1; i <= conLen(c);i++)
{
info(conPeek(c,i));
info(conPeek(v,i));
}
}
return ret;
}
==============================================================================
// To Avoid Null Values from ItemControl Table in //lookup
queryBuildDataSource.addRange(fieldnum(ItemControl,
Onhand)).value(SysQuery::valueNotEmptyString());
queryBuildDataSource.addRange(fieldnum(ItemControl,
Onhand)).value('!=0.00');
============================================================================
Types of Lookup :
3. Looup For one table :
public void lookup()
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(custTable), this);
sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
sysTableLookup.addLookupMethod(tablemethodstr(CustTable,Name));
queryBuildDataSource = query.addDataSource(tableNum(CustTable));
queryBuildRange = queryBuildDataSource.addRange(fieldNum(CustTable, AccountNum));
queryBuildRange.value();
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
//super();
}
4. Multi Select Lookup :
Today i m gonna discuss a concept
that will often used in many situations.Somtimes there comes a situation in
which we want to select multiple rows from lookups that is, we want to display
multiple selected values based on the selection of rows from lookups. So this
behaviour can easily be achieved using SysLookMultiSelectCtrl class.
Steps to follow:
Create a Query named StudentCourse that
contains 2 darasources say, Student & Course.
The figure below shows the structure
of the two tables. Here Course field
in Student table acts as a foreign key.
The below figure shows the StudentCourse Query used.
Use only those field
that you want to show on the form or lookup.
Now create a new form named MultiSelectLookupCtrl and
add a StringEdit control named as TestCtrl in the design
node.Set its AutoDeclaration property to "Yes" so that we can
access this control from X++ code.
Now override the following methods
and write the following code.
In the ClassDeclaration of the form
write the below code.
public class FormRun
extends ObjectRun
{
SysLookupMultiSelectCtrl msCtrl;
}
Override the init method of the form and place the below code
public void init()
{
super();
// TestCtrl - Name of control on which you want a lookup.
// StudentCourse - Query to get the lookup data
msCtrl = SysLookupMultiSelectCtrl::construct(element, TestCtrl, querystr(StudentCourse));
}
That's it, Now let's see how the selected rows are returned from the lookup.
{
SysLookupMultiSelectCtrl msCtrl;
}
Override the init method of the form and place the below code
public void init()
{
super();
// TestCtrl - Name of control on which you want a lookup.
// StudentCourse - Query to get the lookup data
msCtrl = SysLookupMultiSelectCtrl::construct(element, TestCtrl, querystr(StudentCourse));
}
That's it, Now let's see how the selected rows are returned from the lookup.
On clicking the Ok button all the selected values are returned in the String control.
To get the values and RecId of the selected rows, simply override the modified method of the TestCtrl and add the below code.
public boolean modified()
{
boolean ret;
container c,v;
int i;
ret = super();
if (ret)
{
c = msCtrl.get(); // get RecIds of the selected rows
v = msCtrl.getSelectedFieldValues(); // get actual value of the selected rows
for (i = 1; i <= conLen(c);i++)
{
info(conPeek(c,i));
info(conPeek(v,i));
}
}
return ret;
}
==============================================================================
How to Aviod the null values from Lookup() in AX2009
queryBuildDataSource.addRange(fieldnum(ItemControl,
Onhand)).value(SysQuery::valueNotEmptyString());
queryBuildDataSource.addRange(fieldnum(ItemControl,
Onhand)).value('!=0.00');
============================================================================
Types of Lookup :
Types
of Lookups :
1. Creating an automatic lookup
Developed based
on table relations, and appear automatically.
·
Create
Field to CustGroup table ( Type – string , Name – PaymMode, Extended data type
– CustPaymMode).
·
Add
new field to Overview field group of
table.
·
Open
EDT Relation Migration Tool ( Tools >> Code Upgrade ).
·
Select
CustGroup on left, Change Migration Action for PaymMode – Migrate and Click
Migrate Single table
·
Go
to Accounts Receivable \ setup \Customers\Customer groups.
We find automatic lookup generated for
Method of Payment.
Lookup columns can be controlled in
several different places.
Ø
Relation fields, on either an extended data type or a table
itself, are always shown on lookups as columns
Ø
Fields defined in the table's TitleField1 and TitleField2
properties are also displayed as lookup columns
Ø
The first field of every table's index is displayed as a column
Ø
The index fields and the TitleField1 and TitleField2 properties
are in effect only when the AutoLookup field group of a table is empty.
Otherwise, the fields defined in the AutoLookup group are displayed as lookup
columns, along with the relation columns.
Ø
Duplicate columns are shown only once.
Ex :
Add PaymSumBy to Autolookup Group of CustPaymModeTable.
We
get 3 fields in lookup . We can add display methods to Auto Lookup group to get
them in lookup.
2.
Creating a lookup dynamically
Open
the VendTable table in the AOT, and create a new method:
public
static void lookupVendorByCurrency(
FormControl
_callingControl,
CurrencyCode
_currency)
{
Query
query;
QueryBuildDataSource
qbds;
QueryBuildRange
qbr;
SysTableLookup
lookup;
query
= new Query();
qbds
= query.addDataSource(tableNum(VendTable));
qbr
= qbds.addRange(fieldNum(VendTable,Currency));
qbr.value(queryvalue(_currency));
lookup
= SysTableLookup::newParameters(
tableNum(VendTable),
_callingControl,
true);
lookup.parmQuery(query);
lookup.addLookupField(
fieldNum(VendTable,
AccountNum),
true);
lookup.addLookupField(fieldNum(VendTable,Party));
lookup.addLookupField(fieldNum(VendTable,Currency));
lookup.performFormLookup();
}
|
In
the AOT, open the CustTable form, and override the lookup()
method of the VendAccount field on the CustTable data source
with the following code:
public void
lookup(FormControl _formControl, str _filterStr)
{
VendTable::lookupVendorByCurrency(
_formControl,
CustTable.Currency);
}
An optional boolean value,
which specifies that the current control value should be highlighted in the
lookup. The default is true
|
3.
Use form to build
Lookup
:
Ex : Lookup with
Tab pages or a search filter.
Modify Standard
customer account lookup to display only active customers.
v
Create
a new form CustLookup . Add Data source ( name – CustTable, Table – CustTable,
Index – AccountIdx, AllowCheck , AllowEdit , AllowCreate, AllowDelete – No ,
OnlyFetchActive – Yes.)
Security checks
should be disabled ( AllowCheck – no ) , To increase performance –
OnlyFetchActive ( yes).
v
Change
Form Design Properties ( Frame – Border , WindowType – Popup).
v
Add
new grid – (Name – Customers, ShowRowLabels – No , DataSource – CustTable)
ShowRowLabels –
To hide Grids row labels
v
Add
new String Edit to Grid – ( Name –
AccountNum, AutoDeclaration – Yes, DS – CustTable, DataField – Accountnum).
v
Add
new Reference group control to grid – Name – Name, DS - CustTable, Reference Field – Party.
v
Add
one more string Edit to Grid , Name – phone, DS – Custtable, Datamethod- Phone
v
Add
New ComboBox, to grid ( Name – blocked, DS – CustTable, DataField – Blocked)
v
Override
following form methods
public
void init()
{
super();
element.selectMode(AccountNum);
}
|
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);
}
|
v
Override
init() of CustTable Ds.
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);
}
|
v
Locate
CustAccount Extended Data type in AOT , Change property ( FormHelp –
CustLookup)
v
Go
to Sales and Marketing \common \SO \All SO
Notice Customer
Account lookup is different, and it includes only active customers.
4.
Building Tree
Lookup:
We use Budget
Model Tree Class and Will demonstrate how to build a budget model tree lookup.
class BudgetModelTree
{
FormTreeControl tree;
BudgetModelId modelId;
}
public static BudgetModelTree construct(
FormTreeControl _formTreeControl,
BudgetModelId _budgetModelId = '')
{
return new
BudgetModelTree(
_formTreeControl,
_budgetModelId);
}
public void new(
FormTreeControl _formTreeControl,
BudgetModelId _budgetModelId)
{
tree = _formTreeControl;
modelId = _budgetModelId;
}
|
private TreeItemIdx createNode(
TreeItemIdx _parentIdx,
BudgetModelId _modelId,
RecId _recId)
{
TreeItemIdx itemIdx;
BudgetModel model;
BudgetModel submodel;
model =
BudgetModel::find(HeadingSub::Heading, _modelId);
itemIdx =
SysFormTreeControl::addTreeItem(
tree,
_modelId + ' : ' + model.Txt,
_parentIdx,
_recId,
Chapter 2
87
0,
true);
if (modelId == _modelId)
{
tree.select(itemIdx);
}
while select submodel
where submodel.ModelId == _modelId
&&
submodel.Type == HeadingSub::SubModel
{
this.createNode(
itemIdx,
submodel.SubModelId,
submodel.RecId);
}
return itemIdx;
}
public void buildTree()
{
BudgetModel model;
BudgetModel submodel;
TreeItemIdx itemIdx;
tree.deleteAll();
tree.lock();
while select RecId, ModelId from model
where model.Type ==
HeadingSub::Heading
notExists join submodel
where submodel.SubModelId ==
model.ModelId &&
submodel.Type == HeadingSub::SubModel
{
itemIdx = this.createNode(
FormTreeAdd::Root,
model.ModelId,
model.RecId);
SysFormTreeControl::expandTree(tree,
itemIdx);
}
tree.unLock(true);
}
|
§
New
form – BudgetModelLookup ( Frame – Border, WindowType – Popup).
§
New
Tree control to design ( Name – modelTree)
§
Form’s
class declaration ,
BudgetModelTree
budgetModeltree;
Override
the form's init() method with the following code:
public void init()
{
FormStringControl callingControl;
callingControl =
SysTableLookup::getCallerStringControl(
this.args());
super();
budgetModelTree =
BudgetModelTree::construct(
ModelTree,
callingControl.text());
budgetModelTree.buildTree();
}
|
Override
the mouseDblClick() and mouseUp() methods of the ModelTree control
with
the following code, respectively:
public int mouseDblClick(
int _x,
int _y,
int _button,
boolean _ctrl,
boolean _shift)
{
int ret;
FormTreeItem formTreeItem;
BudgetModel budgetModel;
ret = super(_x, _y, _button, _ctrl,
_shift);
formTreeItem =
this.getItem(this.getSelection());
select firstOnly SubModelId from
budgetModel
where budgetModel.RecId ==
formTreeItem.data();
element.closeSelect(budgetModel.SubModelId);
return ret;
}
Returns User –
Selected value from the tree node back to calling method and closes lookup.
public int mouseUp(
int _x,
int _y,
int _button,
boolean _ctrl,
boolean _shift)
{
int ret;
ret =
super(_x,_y,_button,_ctrl,_shift);
return 1;
}
Make sure the lookup doesn’t close
while the user expands or collapses the treenodes.
|
In the AOT, open the BudgetModel table, and change its lookupBudgetModel()
method with the following code:
public static void lookupBudgetModel(
FormStringControl _ctrl,
boolean _showStopped = false)
{
Args args;
Object formRun;
args = new Args();
|
args.name(formStr(BudgetModelLookup));
args.caller(_ctrl);
formRun = classfactory.formRunClass(args);
formRun.init();
_ctrl.performFormLookup(formRun);
}
|
§
Budgeting\Common\Budget
register entries. Start creating a new entry by clicking on Budget Register
entry button in Action pane, and expand the Budget model lookup.
5.
Displaying A list
of Custom Options
:
Besides lookup
created using Records from DB, we can also use Some external data / Hardcoded
options. These types are used only for Specific tasks, such lists are smaller
as opposed to those of the data – driven lookups.
a)
Use Job
static void PickList(Args _args)
{
Map choices;
str ret;
choices = new Map(
Types::Integer,
Types::String);
choices.insert(1, "Axapta
3.0");
|
choices.insert(2, "Dynamics AX
4.0");
choices.insert(3, "Dynamics AX
2009");
choices.insert(4, "Dynamics AX
2012");
ret = pickList(choices, "",
"Choose version");
if (ret)
{
info(strFmt("You've selected
option No. %1", ret));
}
}
|
Run job , Will give O/p as shown in
fig.
When you click any of the option, You
get msg
You have selected option No. 4
|
Dynamics AX provides a no.of Global
lookup functions,
pickDataArea() shows a list of
Dynamics AX companies.
pickUserGroups() shows a list of user
groups in the system.
pickUser() shows a list of Dynamics AX
users
pickTable() shows all Dynamics AX tables.
pickField() shows table fields. Table number has to be specified
as an argument for the function.
pickClass() shows a list
of Dynamics AX classes
|
b.
To get lookup with Checkbox
appear next to each option.
static void SysListSelectSingle(Args _args)
{
container choices;
container headers;
container selection;
container selected;
boolean ok;
choices = [
["3.0\nAxapta 3.0", 1, false],
["4.0\nDynamics AX 4.0", 2, false],
["2009\nDynamics AX 2009", 3, false],
["2012\nDynamics AX 2012", 4, true]];
headers = ["Version", "Description"];
selection = selectSingle(
"Choose version",
"Please select Dynamics AX version",
choices,
headers);
[ok, selected] = selection;
// Return whether Ok clicked and selected option
if (ok && conLen(selected))
{
info(strFmt(
"You've selected option No. %1",
conPeek(selected,1)));
}
}
|
Select any Option Click Ok,
You have selected option no. 4.
|
c.
To get lookup with Multiple Selection.
static void SysListSelectMultiple(Args _args)
{
container choices;
container headers;
container selection;
container selected;
boolean ok;
int i;
choices = [
["3.0\nAxapta 3.0", 1, false],
["4.0\nDynamics AX 4.0", 2, false],
["2009\nDynamics AX 2009", 3, true],
["2012\nDynamics AX 2012", 4, true]];
headers = ["Version", "Description"];
selection = selectMultiple(
"Choose version",
"Please select Dynamics AX version",
choices,
headers);
[ok, selected] = selection;
if (ok && conLen(selected) > 0)
{
for (i = 1; i <= conLen(selected); i++)
{
info(strFmt(
"You've selected option No. %1",
conPeek(selected,i)));
}
}
}
|
d. Building
A lookup based on Record Description :
Some
lookups, we find Contact person is displayed as a person’s name, even though
the actual table relation is based on Contact person’s ID.
Demo
–
We replace the Vendor Group selection lookup on the vendors form, to show group
description instead of group ID.
ü
Create
new String EDT
( Name –
VendGroupDescriptionExt , Label – Group, Extends - Description )
ü
Open
Vend Table, Create a new method , with code
public edit
VendGroupDescriptionExt editVendGroup(
boolean _set,
VendGroupDescriptionExt
_group)
{
VendGroup vendGroup;
if (_set)
{
if (_group)
{
if (VendGroup::exist(_group))
{
this.VendGroup = _group;
}
|
else
{
select firstOnly VendGroup
from vendGroup
where vendGroup.Name ==
_group;
this.VendGroup =
vendGroup.VendGroup;
}
}
else
{
this.VendGroup = '';
}
}
return VendGroup::name(this.VendGroup);
}
|
ü
In
AOT , find VendTable, form , Locate the Posting Group control inside MainTab \
TabpageDetails \ Tab \TabGeneral \ Upper Group \ Identification .
DataGroup – Empty.
ü
In
the same form, Posting Group , modify the Posting_VendGroup control as [ Datafield – empty , DataMethod –
editVendGroup]
ü
Override
the Lookup() method of Posting_VendGroup control, with
public void lookup()
{
this.performTypeLookup(extendedTypeNum(VendGroupId));
}
ü
Accounts
Payable/common/vendors/Allvendors, Select record and click edit ,
e. Building the Browse for Folder Lookup :
1. Demo : To create a new field and control
named – Documents in GL parameters form, to store folder
path.
·
AOT
>> LedgerParameters table, create a new field ( Type – String , Name –
Document Path, Label- Documents,EDT-Filepath)
·
Add
newly created field to bottom of General Field group
·
Open
LedgerParameters form, create a method,
Public str
filePathLookupTitle()
{
Return “Select document folder ”;
}
·
GL
\Setup\GeneralLedger parameters,
2. Allow Users to Create new folder by adding Make New Folder.
Delete
filePathLookupTitle() from LedgerParameters form, and override lookup() of
DocumentPath field ,
public void
lookup(FormControl _formControl, str _filterStr)
{
FilePath path;
path = WinAPI::browseForPath(
element.hWnd(),
"Select document folder
extended");
LedgerParameters.DocumentPath
= path;
LedgerParameters_ds.refresh();
}
|
Make
New folder button
public void lookup(FormControl _formControl, str _filterStr)
{
FilePath path;
path = WinAPI::browseForFolderDialog(
"Select document folder extended",
LedgerParameters.DocumentPath,
true); // shows –
makeNewFolder button appear
LedgerParameters.DocumentPath = path;
LedgerParameters_ds.refresh();
}
|
f.
Building a lookup for Selecting File :
Demo : To create a
new control called Terms & Conditions in the Form Setup form in Procurement
and sourcing module which allow storing
a path to text document.
*
In
AOT VendFormLetterParameters table, create a new field with ( type – string ,
Name –TermsAndConditions, Label - Terms
& Conditions, EDT – FilenameOpen)
*
Add
field to PurchFormLetterParameters form , create following methods.
// Contains text to Display
as Lookup Title
public str
fileNameLookupTitle()
{
return "Select Terms
& conditions document";
}
|
// Strips file name part and returns
the directory path to the lookup to be used as a starting point.
public str fileNameLookupInitialPath()
{
container file;
file = fileNameSplit(
VendFormletterParameters.TermsAndConditions);
// To process the stored file path.
return conPeek(file ,1);
}
|
// Detect current value in
the field , and extracts the filename
to be displayed on lookup.
public str
fileNameLookupFilename()
{
Filename path;
Filename name;
Filename type;
[path, name, type] = fileNameSplit(
VendFormletterParameters.TermsAndConditions);
return name + type;
}
|
// Displaying a list of
allowed file extensions.
public container
fileNameLookupFilter()
{
#File
return
[WinAPI::fileType(#txt), #AllFilesName+#txt];
}
fileType() – Converts file extensions to their
textual representation
|
*
Procurement
and sourcing \setup \ Forms \Form setup under, Purchase order tab,
Limitations :
1.
Require
to create number of methods on the caller form.
2.
It
will not work with multiple file lookups on same form.
To overcome the limitations ,
Remove all four methods and overriding
lookup() of TermsAndconditions field ,
public void lookup(FormControl
_formControl, str _filterStr)
{
FilenameOpen file;
Filename path;
Filename name;
Filename type;
#File
[path, name, type] = fileNameSplit(
VendFormLetterParameters.TermsAndConditions);
file = WinAPI::getOpenFileName(
element.hWnd(),
[WinAPI::fileType(#txt),
#AllFilesName+#txt],
path,
"Select Terms & conditions
document",
"",
name + type);
if (file)
{
VendFormLetterParameters.TermsAndConditions
= file;
VendFormLetterParameters_ds.refresh();
}
}
|
g. Creating
a color picker lookup :
Open
AOT >> Company Info table , create new field ( Type – Integer, Name –
Company Color, EDT – CCColor)
Open
OMLegalEntity – locate TopPanel, Body \Content\Tab\Genenral , Add new IntEdit
control ( Name – CompanyColor, AutoDeclaration – yes, LookupButton – Always,
ShowZero – No, ColorScheme – RGB , Label – Company Color)
In
same form create new method
public edit CCColor
editCompanyColor(
boolean _set,
CompanyInfo _companyInfo,
CCColor _color)
{
if
(_companyInfo.CompanyColor)
{
CompanyColor.backgroundColor(_companyInfo.CompanyColor);
}
else
{
CompanyColor.backgroundColor(
WinAPI::RGB2int(255,255,255));
}
return 0;
}
|
No comments:
Post a Comment