With all the .Net managed-host user-controls that I’ve created so far, I found the need to upload documents from one of them into the Dynamics-Document-Store. The specific example in question was the Desktop-Publishing control that I used for the invoice printing PoC: [https://community.dynamics.com/ax/b/dynamicsax_wpfandnetinnovations/archive/2013/02/23/creating-desktop-publishing-documents-in-dynamics-part-3.aspx#.UahsO0DFX3Q].
As soon as the document has been created, I then need to save it (in memory) as either XPS or PDF (read-only-format) and then upload it back into the Collections module (for the credit controllers).
There is a bit of standard X++ code that will do this very job and I’ve placed it into a class in order to expose the functionality via a .Net proxy:
X++ |
class BillPrintRunDocumentUpload { Filename fileName; RefRecId refRecId; RefTableId refTableId; } |
public Filename parmFilename(Filename _filename = filename) { filename = _filename; return filename; } |
public RefRecId parmRefRecId(RefRecId _refRecId = refRecId) { refRecId = _refRecId; return refRecId; } |
public RefTableId parmRefTableId(RefTableId _refTableId = refTableId) { refTableId = _refTableId; return refTableId; } |
publicvoid uploadDocument() { DocuRef docuRef1, docuRef2; DocuActionArchive docuActionArchive; ; docuRef1.RefRecId = refRecId; docuRef1.RefTableId = refTableId; docuRef1.RefCompanyId = curext(); docuRef1.TypeId = 'File'; docuRef1.Restriction = DocuRestriction::External; docuRef1.Notes = 'Auto uploaded from bill invoice run.'; docuRef1.insert(); ttsBegin; selectforupdate docuRef2 where docuRef2.RecId == docuRef1.RecId; docuActionArchive = DocuAction::newDocuRef(docuRef2); docuActionArchive.add(docuRef2, fileName); ttsCommit; } |
· You can use this class as a .Net proxy by dragging and dropping from the Application-explorer into your Wpf User-control project.
You can then invoke the functionality by filling in all the class properties and calling the “uploadDocument” method from the client. It’s relatively simple; all you need is theTableId and the RecId of the record you wish to attach the document to (as in the following examples):
C#: Upload a document to the Client container |
// upload document to Customer BillPrintRunDocumentUpload objLegalBillPrintRunDocumentUpload = newBillPrintRunDocumentUpload(); objBillPrintRunDocumentUpload.parmFilename(Filename); objBillPrintRunDocumentUpload.parmRefTableId(objCustTable.TableId); objBillPrintRunDocumentUpload.parmRefRecId(objCustTable.RecId); objLegalBillPrintRunDocumentUpload.uploadDocument(); |
C#: Upload a document to the Customer transactions container |
// upload document to Customer transactions CustTrans objCustTrans = newCustTrans(); objCustTrans = CustTrans.findFromInvoice(objBillTable.BillId); objBillPrintRunDocumentUpload.parmFilename(Filename); objBillPrintRunDocumentUpload.parmRefTableId(objCustTrans.TableId); objBillPrintRunDocumentUpload.parmRefRecId(objCustTrans.RecId); objBillPrintRunDocumentUpload.uploadDocument(); |
Auto-uploading the document after invoice-production has the effect of adding an attachment icon on the main collection screen as shown below. Clicking on the document icon opens a dialog showing the invoice that’s been auto-uploaded.
This can be achieved from any 3rd party application that produces your invoices so long as it has the capability to call the .Net proxy class defined above.
REGARDS