Thursday, 19 February 2015

Capturing infolog messages in AX 2012

Today I am going to explain how to capture infolog messages for a particular record and show those logs on click of a log button on a form.

1) Create a job which inserts records into a table, prints some info messages and capture them.

logTable contains three fields EmpId, name and info. info is a field created with EDT infologData and visible property is set to NO. info is a container which stores the infolog messages for the particular record.

static void logs(Args _args)
{
     logTable       insertLog;
 
     NumberSeq  numberSeq;
     InfologData  msg;

     ttsbegin;
     insertLog.initValue();

     numberSeq                          =   NumberSeq::newGetNum(InventParameters::numRefEmpID());
     insertLog.EmpId           =   numberSeq.num();
     insertLog.Name                  =   'ABC';

     info(strFmt("%1", insertLog.EmpId));
     info(strFmt("%1", insertLog.Name));
     info(strFmt("Employee with %1 & name %2 created successfully", insertLog.EmpId,insertLog.Name));
     msg        =    infolog.infologData();
     insertLog.Info = msg;

     insertlog.insert();
     infolog.clear();

     ttscommit;
}

NOTE :
i) Save compile and run this job. EmpId is generated through number sequence and name is hard coded. These two values are inserted into table.

ii) The info stored for this record are :

EMPID-0001
New
Employee with EMPID-0001 & name ABC created successfully

2)  Now create a form with grid showing the logTable datasource fields and button named log.
Write the following code in clicked method of the button

void clicked()
{
    InfologData  msg;

    msg = logTable.info;
    infolog.import(msg);
}

Now when you select this particular record and press the log button the infolog messages stored for this record are displayed in info.

No comments:

Post a Comment