≡ Menu




Document Attachment through X++ code Dynamics Ax 2012 R3.

During development there is requirement to import attached form physical location and shown in attachment to Dynamics AX.

 

I found X++ snippet from following links

http://theaxapta.blogspot.com/2013/04/x-code-for-document-attachment.html

http://microsoftdax.blogspot.com/2012/06/x-code-for-document-attachement-in-ax.html

 

 

In Dynamics Ax 2012 there is one table and one class which are responsible for holding and load document from file location and copied it to specific location.

 

  • DocuRef table
  • DocuActionArchive class

 

 

But there is one more thing, here we required two more reference, one is record recId and table where this rec Id exists. For example if we have to attached document with customer than we required the Recid of customer and table number for customer table.

 

Following code is attaching file form c drive and attached to Customer with account num “US-004” In demo data

 

static void Job3(Args _args)

{

DocuRef docuRef;

DocuActionArchive archive;

CustTable _custtable;

str _name;

;

 

_name=@"c:\\ddddd.docx";

select RecId from _custtable where _custtable.AccountNum =="us-004";

 

if (_custtable!=null)

{

ttsBegin;

docuRef.clear();

docuRef.RefRecId = _custtable.RecId;

docuRef.RefTableId = tableNum("custtable");

docuRef.RefCompanyId = curext();

docuRef.Name = _name;

docuRef.TypeId = 'File';

docuRef.insert();

archive = new DocuActionArchive();

archive.add(docuRef, _name);

ttsCommit;

}

 

 

}

 

When I run this X++ test job I found document is attached as follow

 

FileDD

{ 0 comments… add one }

Leave a Comment