Document Handling Ax 2009

Hi Dear All,

I need to upload some pdf report into document handler based on customer id using Ax Job. I created job for that. but it is not working properly. i need to ur help to get solve this.

static void DocumentHandling(Args _args)
DocuRef docuRef;
DocuValue docuValue;
smmBusRelTable smmBusRelTable;
System.String[] fileNames;
int fileCount, i;

str fileName, trimmedFileName,docName;
BinData binData;
custAccount custAcc;


binData = new BinData();
fileNames = System.IO.Directory::GetFiles(@“D:\Test”);

fileCount = fileNames.get_Length();

for (i=0; i<fileCount; i++)
fileName = fileNames.GetValue(i);

trimmedFileName = substr(fileName, strscan(fileName, ‘\’, strlen(fileName), -strlen(fileName))+ 1, strlen(fileName));

if (trimmedFileName)
trimmedFileName = strreplace(trimmedFileName, “.PDF”, “”);

docName = trimmedFileName;
trimmedFileName = substr(trimmedFileName,1,5);
custAcc = trimmedFileName;

select firstonly smmBusRelTable
where smmBusRelTable.smmCustAccount == custAcc;


if (smmBusRelTable)
docuValue.File = binData.getData();
docuValue.OriginalFileName =fileName;
docuValue.FileType =‘PDF’;
docuValue.FileName = NumberSeq::newGetNum(DocuParameters::numRefDocuNumber(),false).num();

docuRef.ValueRecId = docuValue.RecId;
docuRef.RefTableId = tableNum(smmBusRelTable);
docuRef.RefRecId = smmBusRelTable.RecId;
docuRef.RefCompanyId = curext();
docuRef.TypeId = “OrderForm”;
docuRef.Name = docName;




What’s not working properly exactly? Why are you using smmBusRelTable? What do you want the documents to be attached TO exactly? If you want them attached to the customer accounts, then CustTable would be correct.

Hi Alex,

I just want to copy that upload file into file Archive location. this doesn’t copy the file. that is the problem.

I have setup file archive location from the parameter setups. it is working when adding document manually via document handling.



Hi Sameera,

Quickly glancing through your code it looks OK. Do you get any error while running this code?

Hi Harish,

Thanks for the reply.

It is working now. [:)]

Thanks all…

Hi Sameera,

Glad that you got the solution working.

Just curious - what was wrong?