Tuesday 2 October 2018

Attach documents or creates notes through X++ in Ax 2012

AX2012: Attach documents or creates notes through X++

Attach documents and create notes for a sales order after reading files from directories.

Documents can be attached to a sales order manually from the following button.








Code snippet to create notes or attach documents


 DocuRef             docuRef;
 DocuActionArchive   docuArchive;
 SalesTable          salesTable = SalesTable::find("SO00001");

 Filename            fileName = @"C\Temp\SalesOrder.docx";

 ttsbegin;

 // Code to create notes
 docuRef.TypeId       = 'Note';
 docuRef.Name         = "Sales order notes";
 docuRef.Notes  = "Checked Postcode: 2000, Select resident type";
 docuRef.Restriction  = DocuRestriction::External;
 docuRef.RefTableId   = tableNum(SalesTable);
 docuRef.RefRecId     = salesTable.RecId;
 docuRef.RefCompanyId = curext();
 docuRef.insert();

 //Code to attach file
 docuArchive = new DocuActionArchive();
 docuArchive.setType(docRef.TypeId);
 docuArchive.add(docuRef, fileName);

 ttscommit;

No comments:

Post a Comment