Working with document attachments

Draft comment:
This topic only applies to BAW, and is located in the BAW repository. Last updated on 2025-03-13 12:15
Document attachments can be associated with process instances. These can be added through coach controls or through programmatic additions.
The relevant JavaScript components are:
TWDocument
The description of a document.
tw.system.findDocumentByID()
Finds a document from its ID.
TWProcessInstance.documents
An array of TWDocument objects associated with an instance of a process.
TWProcessInstance.addDocument()
Adds a document to a process instance.
TWProcessInstance.findDocuments()
Locates documents associated with the current instance.
Note: The addDocument() function will not work when called from JavaScript locally coded in a process activity but works fine when coded in a general service.

Using the addDocuments() method

The addDocuments() method has the following parameters:
type (String)
Either TWDocument.Types.URL or TWDocument.Types.File.
name (String)
Name of the document.
fileLocation (String)
The path to the file on the server or URI.
hideInPortal (Boolean)
A flag which describes whether or not the document is to be visible in Heritage Process Portal.
createdBy (TWUser)
Draft comment:
need input here
properties (Map)
Draft comment:
need input here
The following code sample illustrates how to use the addDocuments() method.
var myMap = new tw.object.Map();
var hide = false;
var user = tw.system.user;
tw.system.currentProcessInstance.addDocument(
  TWDocument.Types.File,
  "name",
  "C:\\Projects\\WLE\\Images\\ibm.jpg",
  hide,
  user,
  myMap);