Hi I am trying to run the following code from a batch job
here is what my run method looks like: this works perfectly fine on client but as soon as i run it in batch i get
this exception :
Microsoft.Dynamics.Ax.Xpp.ErrorException: Exception of type ‘Microsoft.Dynamics.Ax.Xpp.ErrorException’ was thrown.
at Dynamics.Ax.Application.BatchRun.runJobStaticCode(Int64 batchId) in BatchRun.runJobStaticCode.xpp:line 34
at Dynamics.Ax.Application.BatchRun.runJobStatic(Int64 batchId) in BatchRun.runJobStatic.xpp:line 13
at BatchRun::runJobStatic(Object[] )
at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)
at BatchIL.taskThreadEntry(Object threadArg)
Here is how my run method looks like
public void run()
{
#File
#Define.NewGroup(“New”)
//FileIOPermission filePermission = new FileIOPermission(“custreplace.csv”,‘rw’);
IO iO;
AccountNum accountNum, tempAccountnum;
FileIOPermission filePermission;
CustTable custTable;
FilenameOpen filename = “c:\custreplace.csv”;//To assign file name
Container record;
boolean first = true;
;
filePermission = new FileIOPermission(“c:\custreplace.csv”,#IO_Read);
filePermission.assert();
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
while (iO.status() == IO_Status::Ok)
{
record = iO.read();// To read file
if (record)
{
if (first) //To skip header
{
first = false;
}
else
{
tempAccountnum = conpeek(record, 1);//To peek record
accountNum = conpeek(record, 2);
ttsBegin;
select firstOnly forUpdate custTable where custTable.AccountNum == tempAccountnum;
if(custTable.RecId)
{
custTable.AccountNum = accountNum;
custTable.renamePrimaryKey();
custTable.CustGroup = #NewGroup;
custTable.HGDTempCust=NoYes::No;
custTable.HGDMDMCust=NoYes::Yes;
custTable.update();
ttsCommit;
// this method will updated all other relevent address and Aimd2 and Sic values
//This calls another class that recieves JSON object which is then parsed for Customer details and then customer gets created in AX.
this.createOrganizationId(custTable.AccountNum);
info(‘has been replaced successfully’);
}
else
ttsAbort;
}
}
}
iO = null;
}