Skilled Soft Blog


Dynamics AX 2012 (Moving Attachments while Converting Purchase Requisition to a Purchase Order)

Dynamics AX 2012 (Moving Attachments while Converting Purchase Requisition to a Purchase Order)

UNDERSTANDING THE LOGIC ABOUT DOCUMENT STORAGE

To start with, you need to understand how the attachments are processed in Dynamics AX.

There are three tables that we will be looking At in Attachments.

We will use MSSQL to track documents

declare @recid varchar(10) = –Put the recid of the record you want to view the attachments

select VALUERECID,TYPEID, name,* from DocuRef where REFRECID = @recid

There are two fields that are important in this table VALUERECID and TYPEID

Valuerecid contains the link to the second table which is DOCUVALUE and it is only used when the item attached is a file or a document. To know if the attachment is a file or document use the second field Typeid

The second table is DOCUVALUE and the link between DocuRef and DOCUVALUE is VALUERECID in DocuRef and RECIDin DOCUVALUE

select FILENAME,* from DOCUVALUE where RECID in(‘VALUERECID in Docuref’)

To get the file path of where AX 2012 stored the files query table DOCUPARAMETERS and take the field ARCHIVEPATH

select ARCHIVEPATH,* from DOCUPARAMETERS where DATAAREAID = ‘Company id’

LOGIC ABOUT X++ DOCUMENT ATTACHMENT

From the initial step the main table to save is DocuRef

NB: AX moves the file to the archive location set up and it appends a name to identify the attachement. Dynamics AX has Created a Class to assist with Document Archiving the class is DocuActionArchive

How to do a simple attachment (X++)

DocuRef docuRef; //declare Docuref table

DocuActionArchive archive; //declare the DocuActionArchive class

str _newname;

;

_newname = ‘Transfere from PO’+_name;

docuRef.clear();

ttsBegin; //Insert into the docuref table

docuRef.RefRecId = _refRecId; //Recid of the record you want the attachment to be in

docuRef.RefTableId = _refTableId; //Tableid where the record exists Example Tablenum(Purchrecline)

docuRef.ValueRecId = _valrecid;

docuRef.RefCompanyId = _refCompanyId;

docuRef.Name = _newname; //Name of the document

docuRef.TypeId = _Filetype; //File type

docuRef.Notes = _notes; //File notes if any

docuRef.insert(); //Insert

archive = new DocuActionArchive(); //Create an instance of the class DocuActionArchive

archive.add(docuRef, _path); //Call the menthod Add in the class DocuActionArchive and pass the table docuref and File path

ttsCommit;

IMPLEMENTING IN PURCHASE REQUISITION CONVERTING

At first I created a class PurchReq_PurchOrder_Transfere (Attached bellow) that will assist with attachment using the logic above. Download the attachment to review it.

Next go to the class RequisitionReleaseStrategy which is incharge of Purchase Requisition Convertion to Purchase Order.

In the main Class after all the Processing you can add a code to loop through the Purchreqtable and pass the marked parameters which in this instance is the Record Recid. Here is a modification I did to the Main in RequisitionReleaseStrategy

for (purchReqLine = fds.getFirst(processMarkedRows) ? fds.getFirst(processMarkedRows) : _args.record(); purchReqLine; purchReqLine = fds.getNext())

{

if ((_table != purchReqLine.purchreqtable) && (purchReqLine.purchreqtable != 0))

{

RequisitionReleaseStrategy::Add_document(purchReqLine.purchreqtable); //this is a method to call the class for File transfere

_table = purchReqLine.purchreqtable;

}

}

The add document method is custom here is the code

Public static void Add_document(RecId _recid)

{

PurchReq_PurchOrder_Transfere _document_class = new PurchReq_PurchOrder_Transfere(); //Declare the custom class

PurchReq_PurchOrder_Transfere::main(_recid); //Call the main method in the Custom class

}


Share
  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon

No Comments Yet...

Leave a reply

Name: Required Field.
Email Address: Required Field. Not visible
Website:
Captcha Code: Required Field.
Comment: Required Field.