Interview Questions

Thursday, March 22, 2018

How to use ternary operator in ax 2012

Hi All,

As we all know that we in some scenarios we need to use Ternary operator for reducing code lines. In a single line we can execute multiple cases.
For achieving this, please go through with below code.

Sample Job for ternary operator:

static void GOD_TernaryOperatorEx(Args _args)
{
    int a, b, c;
    ;

    a = 9;
    c = 8; 
         
    b = (a < 10 ) ? info ("Yes") : info ("No");
   In above line of code we are executing single condition or in other word we can say "If" Condition.
   In this condition we are just testing that "A is greater than 10 or not. If it is, then it will generate       info with "Yes"".

    Or

    b = (a < 10 ) ? ((a < c) ? info ("Yes") : info ("Nope")) : info ("No");
   In above line of code we are executing multiple conditions or in other word we can say "If and else if" Condition.
   In this condition we are testing that "A is greater than 10 or not. If it is not then it will print No, else it will again check that A is greater than "C" or not. If yes then it will print Yes else it will show Nope.
}

Tuesday, March 20, 2018

Use Temporary Table as form datasource in ax 2012

Hi All,

In many scenarios we need to use temporary table as form data source. So below steps are used to achieve this target.

Step 1 - Create a temporary table and make "Table Type" property as "TempDB"
Step 2 - Create a class to fetch or generate the data and insert into temporary table.
Step 3 - Create a method in class for executing your code.

For ex- 
public TempTableTmp  GenerateTempTable()
{
    TempTableTmp       tempTable;
    ;

    Write your logic and insert into temporary table then write below line:
    return tempTable;
}

Step 4 - Create a form and used temporary table created in step 1 as data source.

Step 5 - Override init method at form data source level.

Step 6 - In this method we need to instatiate the class which we have developed at step 2

For Ex - 
public void init()
{
TempTableClass temptableclass = new TempTableClass();

super();

tempTable = temptableclass.GenerateTempTable();

TempTableTmp.linkPhysicalTableInstance(tempTable);
//In above line if you will not use "LinkPhysicalTableInstance" method then you will not get the data on form.


Step 7 - Create a display type menu-item and place at your desired place.

It will solve your issue.