Expand my Community achievements bar.

Dynamically add attachment in onAssign

Avatar

Former Community Member
Hello,



I've got problems dynamically adding attachments using :



var data = new ActiveXObject("EPSDK.BinaryData");

data.LoadFromFile( "c:\\tmp\\mfile.xls" );

WorkItem.AddAttachment( "expense.xls", 1, data );



It says object(workitem) doesn't support this property or method...



Does it suits dynamical attachment of files?



Thank you
6 Replies

Avatar

Former Community Member
Damoon,



The AWS EPSDK is not accessible from the process level. An easy work-around would be to port the script over to an ASP and call from within the process map and\or instantiate a custom DLL.



Jon

Avatar

Former Community Member
Damoon,



It is quite possible to add/update/delete attachments automatically in the workflow. The code below was used to 'clean up' a log field from the form and add contents of that field into an attachment. (In JScript for AWS 6.2, this is not complete script, but should give you enough to work with.)



===start script===



//create file system object

oFSO = new ActiveXObject("Scripting.FileSystemObject");



//open/create files

oFile = oFSO.OpenTextFile(strFileName, ForAppending, true);



//Build the History line.

strHistoryLine = WorkItem.getFieldValue("txtHistory");



oFile.Write(strHistoryLine);



//then close and clean up

oFile.Close();



//and then add the file into the attachments collection

var oAtt = Agent.createObject("attachment");



//attachment name must be unique so add datetime to it

oAtt.name = "(Automated) History up to " + TimeStamp+".txt";

oAtt.get(strFileName, true);

WorkItem.attachments.append(oAtt);

Agent.log("Attachment was created to workflow");



===end script===



The time when you may not be able to use the code is in the OnAssign of a initiating task - the workitem object is not created yet by the time OnAssign is run.



Hope this helps,

Sanna

Avatar

Former Community Member
Sanna,



What if I wanted to loop through the attachments and print them to pdf files as part of a step?



Thanks,



Bill

Avatar

Former Community Member
Not a problem, Bill.



Unfortunately for this I do not have sample code ready - but basically, you'd access the Attachments collection to loop through all attachments and then either submit to Central for processing or use the CreatePDF method if you have Form Server installed.



(AWS does not inherently have the functionality, but if you have any other tool available that you can use, such as those mentioned, you'll be fine)



Look at the manuals, they have some good sample code for Attachment management. Which tools do you have available?



Good luck,

Sanna

Avatar

Former Community Member
Bill \ Sanna,<br /><br />Unsure if Adobe Form Server has the ability to create PDF from attachment files ( doc, txt, xls ) etc... If that's the case then you would require 3rd party software that will generate a PDF - Adobe PDF Writer perhaps.<br /><br />Check below for an example of looping thru the envelopectl. After you retreive the physical file then I believe some sort of WinAPI call may have to be made in order to send the file to the Adobe Print Queue.<br /><br />// are there any attachments to speak of<br />var iAttach = WorkItem.attachments.length;<br /><br />if ( iAttach > 0 ) { // not empty<br /> <br /> // instantiate wfattachment object<br /> var oAttach = Agent.createObject("Attachment");<br /> var atloc, atname; <br /> <br /> // loop throu the wfattachment collection<br /> for ( i=0;i<iAttach;i++ ){<br /> <br /> // grab the attachment object from the attachment collection<br /> oAttach = WorkItem.attachments.item(i);<br /> <br /> /* Attachments are stored in the database, so accessing this property<br /> causes Workflow Agent to copy the attachment from the database to the file system. Workflow Agent<br /> determines the precise file location. */<br /> // ie. "F:\Program Files\Adobe\Workflow Server\TMP\jcd3m6peep6e9k8kwnp2xf4sbw.txt"<br /> atloc = oAttach.location;<br /> <br /> // get the name of the attachment<br /> atname = oAttach.Name;<br /> <br /> oAttach = null;<br /><br />/* Now that you have the physical location and name of the file you can make a WINAPI to send it to the Adobe Print Queue. */<br />}