Batch error Microsoft.Dynamics.Ax.Xpp.ErrorException

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();

//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;

}

My guess without doing any debugging is that you tested your code on client but the batch is invalid when running on AOS, or the AOS service account doesn’t have permissions to read the file.

If it’s not the case, do some analysis…

The error says that an exception was thrown at line 34 of at BatchRun.runJobStaticCode(). What code do you have at that line? I looked into my AX 2012 R3 but I suspect you have a different version with different code.

You can also debug the code. Running it in batch doesn’t have to be necessary to reproduce the problem, nevertheless ensure yourself that the code runs on AOS; it may also require running in CIL instead of X++.

Hi Martin,

Thanks a lot for your advice i investigated as per your advice, I was able to debug this and there were 2 problems,code was not running on AOS and secondly the third party Dll i was using Newtonsoft.json object was adding an additional jarray when we are trying to run on the server side. this is very weird when we compared the cleint side Json . we modified the method a little to make it work. now it appears to be working alright.

BatchRun.runJobStaticCode() is different because i am on R2 and you are on R3.