Skip to main content

Adding lookup method on Form Reference Group AX 2012

Reference Group Control lookups in AX 2012

With the addition of reference groups fields the AX forms including the dialog form gives a rich control called theFormReferenceGroupControl. With this post, I will show you how to add a reference field in the batch dialog form and add a filtered query controlled drop down.

I am going to show with a EcoResCategoryId field. The requirement is to filter out categories with Level 3 and present in the batch dialog dropdown.
 

Class Declaration:
 Declare the warehouse and category fields and dialog fields as below.

InventLocationId            inventLocationId;
EcoResCategoryId            EcoResCategoryId;
DialogField                 DialogInventLocationId,DialogEcoResCategoryId;

Dialog Method:
public Object dialog()
{
    dialog    dialog = new DialogRunbase("@ZON2996",this);


    DialogEcoResCategoryId   = dialog.addField(extendedTypeStr(EcoResCategoryId),"Category");
    DialogInventLocationId   = dialog.addField(extendedTypeStr(InventLocationId),"Warehouse");


    return dialog;
}

DialogPostRun method should be overridden to enable the lookup method of the fields
public void dialogPostRun(DialogRunbase _dialogloc)
{
    super(_dialogloc);
    _dialogloc.dialogForm();
     _dialogloc.dialogForm().formRun().controlMethodOverload(true);
    _dialogloc.dialogForm().formRun().controlMethodOverloadObject(this);
     _dialogloc.formRun().controlMethodOverload(true);
    _dialogloc.formRun().controlMethodOverloadObject(this);

}
Determine the field Id of the control from the dialog form. Personalizing will show you the below form.
From the below form we know that Fld1_1 is the field for the category. Also note that as it is reference group, a Name field is shown that should hold the category information in the string box.


Lookup:
We would need to create a lookup method for the above field as below.
void Fld1_1_lookup()
{
    Query     DropDownquery          = new Query();
    FormControl       frmSTr         = DialogEcoResCategoryId.dialog().formRun().controlCallingMethod();

//Use the SysReferenceTableLookup class instead of SystableLookup class for such reference group control
    SysReferenceTableLookup          sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(EcoResCategory), frmSTr,true);
   
    QueryBuildDataSource     qbds;
    QueryBuildRange          qbr,qbr1;
    ;


    qbds = DropDownquery.addDataSource(tableNum(EcoResCategory));
    qbr  = qbds.addRange(fieldNum(EcoResCategory,Level));
    qbr.value(queryValue(3));
   

    sysTableLookup.addSelectionField(fieldNum(EcoResCategory, Name));
    sysTableLookup.addLookupField(fieldNum(EcoResCategory, ReciD));
    sysTableLookup.addLookupField(fieldNum(EcoResCategory, Name));
    sysTableLookup.addLookupField(fieldNum(EcoResCategory, Code));
    sysTableLookup.parmQuery(DropDownquery);
    sysTableLookup.performFormLookup();

}

Comments

Popular posts from this blog

Important function in x++ for AX 2009 and AX 2012

Important function in X++ I would like to share some important function in x++ Like subStr(), strCmp(),strDel() , strFind (),strfmt () , strLen (),strLwr (),strUpr (),strRep(),systemDateGet(),today(),trunc (),boxExample (),conins(), conLen(), conPeek(), conNull() which seems to easy but some time became very tough to recall in between to coding, so don’t worry and keep coding……. Sub String in X++ // for cut a string from given posititon SubStr("ABCDEFGHIJ",7,-4) returns the text string "DEFG" (the specified sub-string). static void subStr(Args _args) {   str s;   real  r;    ;     r = strLen("jitendraknit@gmail.com");     s = subStr("jitendraknit@gmail.com",12, 2);      print(strFmt("s=%1 and r=%2",s,r));      pause; } String Comparison in X++ static void strCmp(Args _args) {   int i=2;   str s1,s2;    ;      s1="string 1";      //s2...

MS Dynamics AX Interview Questions with Answers

1.  Difference between following: condel :- Use condel to delete one or more items from a container. confind :- Use confind to locate a sequence of items in a container.  conins :- Use conins to insert some items into a container. conlen :- Use conlen to find out how many items there are in a container. connull :- Use connull to explicitly dispose of the contents of a container. conpeek :- Use conpeek to extract an item from a container, and to convert it into another data type   conpoke :- Use conpoke to replace (poke) an item in a container. 2. Difference between edit and display method? Display Indicates that the method's return value is to be displayed on a form or a report. The value cannot be altered in the form or report Edit Indicates that the method's return type is to be used to provide information for a field that is used in  In a form. The value in the field can be edited.      3. Difference between perspectives and table...