Sep 24, 2014

RecVersion(System Field in Table) - On Updation


RecVersion is used for optimistic concurrency control (OCC) and is used by the AOS.    
      
First let us know about Concurrency Controls,
-  Optimistic Concurrency Control (OCC)   
-  Pessimistic Concurrency Control (PCC)
 
        Optimistic Concurrency Control (OCC) helps in increase of database performance at the time of record updation. Pessimistic Concurrency Control locks records as soon as they are fetched from the database for an update, where OC only locks records from the time when the actual update is performed.
 
OCC - Advantages and Disadvantages 
  • Records are locked for a shorter length of time.
  • Records will remain available for other processes to update if they have been selected from the database
  • The update can fail if another process updates the same record. If the update fails, it must be retried. This can  lead to a reduction in database performance.
  Update Conflicts can be handled by catching the UpdateConflict and UpdateConflictNotRecoveredevents.

This pattern is used across AX API's for retrying the update conflicts and if it exceeds the maximum retry count then UpdateConflictNotRecovered exception is thrown.
 
RecVersion use on updation :- 

      Update conflicts are detected by the kernel. It checks the value of the recVersion system field on the table at the time the record is selected for update. This value is matched to the value of the field when the record is subsequently updated.

" When the update is executed, the system checks if the recVersion of the record in the database is equal to the recVersion on the moment the records was selected. If that was the case. The update succeed "
Note : The default value of recVersion is 1. This will changed to a random value(Int32) when a record is updated.


 

 

May 7, 2014

Code to open a display menuitem


MyTable     myTable;

    Args           args;

    MenuFunction    menuFunction;

    ;

    myTable  =  CurrentTableBuffer;

    args = new Args();

    args.caller(element);

    new MenuFunction(menuitemdisplaystr(MenuItemNameOfTheFormWhich   HaveToOpen),MenuItemType::Display);

    menuFunction.run(args);

    super();

Opening a project in AX through the code

static void projectNodeOpen(Args _args)
{ 
    ProjectNode projectType,projectNode;
    ;
    projectType    =  Infolog.projectRootNode().AOTfindChild('Private');
    projectNode   =  projectType.AOTfindChild('EPTest');
    if (projectNode)
    {
        projectNode.getRunNode();
    }
}

May 6, 2014

Turn off/on Synchronize database when making changes to AOT tables


How to turn off/on Synchronize database when making changes to AOT tables.

Static void ShowSysSqlSync (Args _args)

{

    SysGlobalCache  sgc;
    str owner = 'SysSqlSync';
    str key   = 'ShowSysSqlSync';

     ;

    sgc = appl.globalCache();

    sgc.set(owner, key, true/false);

    Info (strfmt (' SqlSync  status : %1', sgc.get (owner, key)));

}

May 5, 2014

"continue" and "break" statements in X++



// Sample job using "continue" and "break" statements in X++
Static void sampleContinueBreak()
{
  int counter;
  
for (counter=1;counter <= 10;counter++)

  {           
     if (counter > 3 && counter < 8)

     {
       continue;

     }
     else if(counter == 9)

     {
        break;

     }
     info(int2str( counter));


  }
 
 info(int2str( counter));
   
}


//One more example

static int sampleSwitch(int x = 5)
{
 ; 

 switch (x)
 { 

  case (1):
  x = 5;

  case (5):
  x = x + 5;

  case (10):
  x = x + 10;
  break;

  case (20):
  x = x + 20;
  break;

  default:
  x = 5;


 }
info(strfmt("Return value is %1", x));
return x;

}







Apr 27, 2014

Like operator in AX





static void Job1(Args _args)
{
    TrvExpTrans trvexp;
    ;
    while select trvexp where  trvexp.Description like "Ai??are"
    {
        info(trvexp.ExpNumber + "------" + trvexp.Description);
    } 


}

Job to create unreconciled expense by using service class in AX2012


Creating unreconciled expense by using service class




static void CreateunreconciledExpense(Args _args)
{
    TrvUnreconciledExpenseRecord newRecord;
    TrvUnreconciledExpenseService service = new TrvUnreconciledExpenseService(); 


    newRecord = new TrvUnreconciledExpenseRecord();
    newRecord.parmCostType('Car Rental');
   // newRecord.parmMerchantId('Bad car rental place');
    newRecord.parmTransactionCurrencyAmount(600);
    newRecord.parmTransactionCurrencyCode('EUR');     
    newRecord.parmTransactionDate(DateTimeUtil::date(DateTimeUtil::addDays(DateTimeUtil::utcNow(), -1228)));


    newRecord.parmUserNetworkAlias('XXXXX'); // pass the username
    newRecord.parmUserNetworkDomain('XXXXXXXXXX'); // Pass the network domian 


    service.createRecord(newRecord);
    info("record created");
}

Job to create expense record by using service classes





Here is the sample job to create expense record  by using service class.


static void createExpLine(Args _args)
{


    TrvExpenseService            expService;    //  Service class
    TrvExpense                   trvExpense;      // Expense Document object
    TrvExpense_TrvExpTable       expenseTable;  // Expense Header data object
    TrvExpense_TrvExpTrans       expenseTrans;  // Expense Line data object
    AifEntityKeyList             entityKeyList; // Entity key list


    TrvExpNumber                 expNum;
    ; 


    // Create the service instance
    expService =  TrvExpenseService::construct(); 


    // Create the document object
    trvExpense = new TrvExpense(); 


    //create the Expense header
    trvExpense.createTrvExpTable();
    expenseTable    = trvExpense.parmTrvExpTable().addNew();
    expenseTable.parmCreatingWorker("000131"); 


     // Create the Line
    expenseTrans    = new  TrvExpense_TrvExpTrans();
    expenseTrans.parmCostType("Car Rental");
    expenseTrans.parmExpType(TrvExpType::CarRental);
    expenseTrans.parmPayMethod("CASH");
    expenseTrans.parmTransDate(today());
    expenseTrans.parmAmountCurr(10);
    expenseTrans.parmProjId("10001");  
    expenseTrans.parmAdditionalInformation("Free Text");  
    expenseTable.createTrvExpTrans().add(expenseTrans);
     // Create Customer


    entityKeyList = expService.create(trvExpense);
    expNum = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(TrvExpTable, ExpNumber));
    info(strfmt("Created Expense: Exp Number: %1.", expNum)); 


}