Interview Questions

Tuesday, September 27, 2016

lookup method in ax 2009

public void lookup(FormControl _formControl, str _filterStr)
{
    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(ProdBOM), _formControl);
    Query query = new Query();
    QueryBuildDataSource qbds;
    QueryBuildRange  qbr;
    ;
    sysTableLookup.addLookupField(fieldnum(ProdBOM, itemid));
    sysTableLookup.addLookupMethod('itemName');
    qbds = query.addDataSource(tablenum(ProdBOM));
    if(Rejection_ProdId.valueStr())
    {
        qbds.addRange(fieldnum(ProdBOM, prodid)).value(Rejection_ProdId.valueStr());
    }
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

public void lookup()
{
    Query                   query = new Query();
    QueryBuildDataSource    qbdsItem;
    QueryBuildDataSource    qbdsInventTableModule;
    QueryBuildDataSource    qbdsInventItemLocation;
    QueryBuildRange         qbrModuleType;
    SysMultiTableLookup     sysTableLookup;
    ;
    qbdsItem = query.addDataSource(tableNum(InventTable));
    qbdsInventTableModule = qbdsItem.addDataSource(tableNum(InventTableModule), "Purch");
    qbdsInventTableModule.relations(true);
    qbdsInventTableModule.fetchMode(QueryFetchMode::One2One);
    qbrModuleType = qbdsInventTableModule.addRange(fieldNum(InventTableModule, ModuleType));
    qbrModuleType.value(queryValue(ModuleInventPurchSales::Purch));
  
    qbdsInventTableModule = qbdsItem.addDataSource(tableNum(InventTableModule), "Invent");
    qbdsInventTableModule.relations(true);
    qbdsInventTableModule.fetchMode(QueryFetchMode::One2One);           
    qbrModuleType = qbdsInventTableModule.addRange(fieldNum(InventTableModule, ModuleType));
    qbrModuleType.value(queryValue(ModuleInventPurchSales::Invent));
          
    qbdsInventTableModule = qbdsItem.addDataSource(tableNum(InventTableModule), "Sales");
    qbdsInventTableModule.relations(true);
    qbdsInventTableModule.fetchMode(QueryFetchMode::One2One);
    qbrModuleType = qbdsInventTableModule.addRange(fieldNum(InventTableModule, ModuleType));
    qbrModuleType.value(queryValue(ModuleInventPurchSales::Sales));
          
    qbdsInventItemLocation = qbdsItem.addDataSource(tableNum(InventItemLocation));
    qbdsInventItemLocation.relations(true);
    qbdsInventItemLocation.fetchMode(QueryFetchMode::One2One);
          
    sysTableLookup = SysMultiTableLookup::newParameters(this, query);
          
    sysTableLookup.addLookupField(fieldNum(InventTable, ItemId));
    sysTableLookup.addLookupField(fieldNum(InventTable, ItemName));
    sysTableLookup.addLookupMethod(tableMethodStr(InventTable, ConfigActive), 1, "Is configuration active?");
    sysTableLookup.addLookupField(fieldNum(InventTableModule, TaxItemGroupId), 2, false, "Purch Item Tax Group");
    sysTableLookup.addLookupField(fieldNum(InventTableModule, TaxItemGroupId), 3);
    sysTableLookup.addLookupField(fieldNum(InventTableModule, TaxItemGroupId), 4);
    sysTableLookup.addLookupField(fieldNum(InventItemLocation, CountGroupId), 5);
    sysTableLookup.performFormLookup();
}


public void lookup()

{
//super();


// Declaration
Query   LookupQuery    =   new Query();

QueryBuildDataSource     LookupQueryBuildDataSource;

QueryBuildRange                  LookupQueryBuildRange;
SysTableLookup CustomSysTableLookup =       SysTableLookup::newParameters(tableNum(CustTable), this);

;

// Add fields that you want in Lookups

CustomSysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));

CustomSysTableLookup.addLookupField(fieldNum(CustTable,Name));

LookupQueryBuildDataSource =

LookupQuery.addDataSource(tableNum(CustTable));

LookupQueryBuildRange=

LookupQueryBuildDataSource.addRange(fieldNum(CustTable,AccountNum));

//LookupQueryBuildRange.value(queryValue(NOYESCOMBO::Yes));

// Execute the Query

CustomSysTableLookup.parmQuery(LookupQuery);

CustomSysTableLookup.performFormLookup();
}

public void lookup(FormControl _formControl, str _filterStr)
{
SysTableLookup sysTableLookup; // systemclass to create //customlookup
Query query;
QueryBuildDataSource qbd;
;
sysTableLookup = SysTableLookup::newParameters(
tablenum(InventTable),
_formcontrol);

// Construct query on the table,
// whose records you want to show as lookup.
query = new Query();
qbd = query.addDataSource(tablenum(InventTable));
qbd.addRange(fieldnum(InventTable,ItemType)).value(SysQuery::value(enum2str
(ItemType::Item)));

// add the fields to the lookup list
sysTableLookup.addLookupfield(fieldnum(InventTable,ItemId));
sysTableLookup.addLookupfield(fieldnum(InventTable,ItemName));

// pass the query as parameter
// system will show the records in the lookup
// as per your query
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();

}

public void lookup()
 {
     //This lookup basis the list criteria on information in 2 tables
     //All display fields come from Table1, Table2 is used for limiting criteria
    
     //super();
    
     //This Next Line initializes the the sysTableLookupClass
     sysTableLookup          sysTableLookup  =
                     SysTableLookup::newParameters(tableNum(<TABLENAME1>), this);
    
     Query                   query           = New Query();
     QueryBuildDataSource    qbdsTbl1, qbdsTbl2;
     QueryBuildRange         qbr;
     ;
    
     //Add Tables to the data source
     qbdsTbl1      = query.addDataSource(tableNum(<TABLENAME1>));
     qbdsTbl2     = qbdsTbl1.addDataSource(tableNum(TABLENAME2));


     //Add Query Ranges to limit List records   
     qbr = qbdsTbl1.addRange(fieldNum(<TABLENAME1>,<RANGEFIELDNAME1>));
     qbr.value(<CRITERIAVALUE>);

     qbr = qbdsTbl1.addRange(fieldNum(<TABLENAME1>, <RANGEFIELDNAME2>));
     qbr.value(<CRITERIAVALUE>);

     qbr = qbdsTbl1.addRange(fieldNum(<TABLENAME1>, <RANGEFIELDNAME3>));
     qbr.value(<CRITERIAVALUE>);
    
     //Since we have multiple tables in the query turn on relations
     qbdsTbl1.relations(true);

     //Add Ranges to the Table2
     qbr = qbdsTbl2.addRange(fieldNum(<TABLENAME2>, <RANGEFIELDNAME4>));
     qbr.value(<CRITERIAVALUE>);
    
     qbdsTbl2.relations(true);

     //The next 2 lines actualy adds the fields that will be displayed in the lookup grid
     sysTableLookup.addLookupfield(fieldNum(<TABLENAME1>, <DISPLAYFIELDNAME>));
     sysTableLookup.addLookupfield(fieldNum(<TABLENAME1>, <DISPLAYFIELDNAME>));
    
     //Hand the created query to the sysTableLookupClass
     sysTableLookup.parmQuery(query);

     //Display the drop down
     sysTableLookup.performFormLookup();

 }




Another example single table with field and table names instead of variable place holders



//Single table example with actual table and field names instead of  place holders
 public void lookup()
 {
     //This lookup basis the list criteria on information in 2 tables
     //super();
     sysTableLookup          sysTableLookup  =
                 SysTableLookup::newParameters(tableNum(salesBillOfLadingJournalTable), this);
     Query                   query           = New Query();
     QueryBuildDataSource    qbdsJT, qbdsBLR;
     QueryBuildRange         qbr;
     ;

     qbdsJT      = query.addDataSource(tableNum(salesBillOfLadingJournalTable));
     qbdsBLR     = qbdsJT.addDataSource(tableNum(salesBLReservation));



     qbr = qbdsJT.addRange(fieldNum(salesBillOfLadingJournalTable,isMaster));
     qbr.value(enum2str(noYes::No));

     qbr = qbdsJT.addRange(fieldNum(salesBillOfLadingJournalTable, custAccount));
     qbr.value((salesBillOfLadingJournalTableMaster.CustAccount));

     qbr = qbdsJT.addRange(fieldNum(salesBillOfLadingJournalTable, masterBLID));
     qbr.value(&quot;&quot;&quot;&quot;);

     qbdsJT.relations(true);

     qbr = qbdsBLR.addRange(fieldNum(salesBLReservation, blOpen));
     qbr.value(enum2str(noYes::Yes));
     qbdsBLR.relations(true);

     sysTableLookup.addLookupfield(fieldNum(salesBillOfLadingJournalTable, BillOfLadingID));
     sysTableLookup.addLookupfield(fieldNum(salesBillOfLadingJournalTable, salesID));
     sysTableLookup.parmQuery(query);

     sysTableLookup.performFormLookup();

 }


public void lookup()
{
    Query   LookupQuery    =   new Query();
    QueryBuildDataSource     LookupQueryBuildDataSource;
    QueryBuildRange                  LookupQueryBuildRange;
    SysTableLookup ItemSysTableLookup =       SysTableLookup::newParameters(tableNum(InventLocation), this);
    ;
    ItemSysTableLookup.addLookupField(fieldNum(InventLocation, InventLocationId));
    ItemSysTableLookup.addLookupField(fieldNum(InventLocation, Name));
    ItemSysTableLookup.addLookupField(fieldNum(InventLocation, InventSiteId));
    LookupQueryBuildDataSource =LookupQuery.addDataSource(tableNum(InventLocation));
    LookupQueryBuildRange=LookupQueryBuildDataSource.addRange(fieldNum(InventLocation,InventSiteId));
    LookupQueryBuildRange.value(queryRange(Site.valueStr(),Tosite.valueStr()));
    ItemSysTableLookup.parmQuery(LookupQuery);
    ItemSysTableLookup.performFormLookup();
}


public void lookup()
{
    Query   LookupQuery    =   new Query();
    QueryBuildDataSource     LookupQueryBuildDataSource;
    QueryBuildRange                  LookupQueryBuildRange;
    SysTableLookup ItemSysTableLookup =       SysTableLookup::newParameters(tableNum(InventItemGroupItem), this);
    ;
    ItemSysTableLookup.addLookupField(fieldNum(InventItemGroupItem, ItemId));
    ItemSysTableLookup.addLookupMethod('itemName');
    ItemSysTableLookup.addLookupField(fieldNum(InventItemGroupItem, ItemGroupId));
    LookupQueryBuildDataSource =LookupQuery.addDataSource(tableNum(InventItemGroupItem));
    LookupQueryBuildRange=LookupQueryBuildDataSource.addRange(fieldNum(InventItemGroupItem,ItemGroupId));
    LookupQueryBuildRange.value(queryRange(ProductGroup.valueStr(),ToProdGroup.valueStr()));
    ItemSysTableLookup.parmQuery(LookupQuery);
    ItemSysTableLookup.performFormLookup();
}

AX2012- Opening an url form AX X++ code

Infolog.lookupurl("www.google.com");

this statement will quickly open google website in default browser.

AX2012- Update/Change FinancialDimension value in X++ code

static void PSV_UpdateOpDivDimension_Items(Args _args)

InventTable inventTable; 
DimensionAttributeValueSetStorage dimStorage; 
DimensionAttribute dimAttrOpDiv; 
DimensionAttributeValue dimAttributeValue;
changeCompany('DAT') 
{
while select forUpdate inventTable 
{
ttsBegin;
dimStorage = DimensionAttributeValueSetStorage::find(inventTable.DefaultDimension);
dimAttrOpDiv = DimensionAttribute::findByName("Operating_Division");

dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttrOpDiv, 'NewValue', true, true);

dimStorage.addItem(dimAttributeValue); 
inventTable.DefaultDimension = dimStorage.save(); 
inventTable.doUpdate();
ttsCommit;


}

//This code updates the items financial dimensions to new values.

Updating the value of existing dimesnions - Default dimension

Here is a code to update the value of particular dimensions for items

InventTable inventTable;

DimensionAttributeValueSetStorage dimStorage;

DimensionAttribute dimAttrOpDiv;

DimensionAttributeValue dimAttributeValue;

while select forUpdate inventTable
{
ttsBegin;
dimStorage = DimensionAttributeValueSetStorage::find(inventTable.DefaultDimension);
dimAttrOpDiv = DimensionAttribute::findByName("DIMENSION NAME);
dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttrOpDiv,'VALUE'truetrue);
dimStorage.addItem(dimAttributeValue);
inventTable.DefaultDimension = dimStorage.save();
inventTable.doUpdate();
ttsCommit;
}
}

Code to check the current user have system administartor rights in AX X++ code

Sometime before I was written a big statement to find out the System admin rights of current user. Later I realized about global function that will help us to find the same.


isSystemAdministrator(): will tell you the current user is having the admin rights or not.


if isSystemAdministrator() return true then the user is having system admin rights, else not a system admin.