Saving a Base64 Document to IBM BAW Embedded Document Store Using ECM Content Toolkit
When building integrations on IBM Business Automation Workflow (BAW), a common requirement is to programmatically save a document — received as a base64-encoded string — into the embedded BPM document store and associate it with a running process instance. This article walks through exactly how to do that using the ECM Content Toolkit’s Content Integration task inside a Service Flow.
Prerequisites
Before you start, make sure the Content Management (SYSCM) toolkit is added as a dependency to your process application:
Process App Settings → Toolkits → Add Content Management (SYSCM)
This toolkit provides the ECMContentStream, ECMProperty, and ECMMultiValue business objects you'll need.
Service Interface
Create a new Service Flow (or Integration Service) with the following input variables:
Get Selcuk’s stories in your inbox
Join Medium for free to get updates from this writer.
Inputs:
mimeType(String) — MIME type of the document (e.g.application/pdf)fileName(String) — Name of the document file (e.g.invoice.pdf)content(String) — Base64-encoded document contentdocumentProperties(List of NameValuePair) — Optional custom metadata key-value pairsinstanceId(String) — The process instance ID to associate the document with
Local (private) variables:
contentStream(ECMContentStream)properties(List of ECMProperty)documentId(String)
Step 1 — Map Document Properties
Add a Script task to your service flow. This script builds the ECM property list from your documentProperties input and also injects the IBM_BPM_Document_ProcessInstanceId property — which is what links the document to the process instance.
function initProperty(name, value) {
var property = new tw.object.ECMProperty();
property.objectTypeId = name;
property.value = value;
return property;
}
tw.local.properties = new tw.object.listOf.ECMProperty();
var props = new tw.object.ECMMultiValue();
props.value = new tw.object.listOf.ANY();
for (var i = 0; i < tw.local.documentProperties.listLength; i++) {
props.value[i] =
tw.local.documentProperties[i].name +
"," +
tw.local.documentProperties[i].value;
}
tw.local.properties[0] = new tw.object.ECMProperty();
tw.local.properties[0].objectTypeId = "IBM_BPM_Document_Properties";
tw.local.properties[0].value = props;
var propInstanceId = initProperty(
"IBM_BPM_Document_ProcessInstanceId",
tw.local.instanceId
);
tw.local.properties.insertIntoList(0, propInstanceId);What’s happening here?
IBM_BPM_Document_ProcessInstanceIdis the key property that tells BAW which process instance this document belongs to. Without it, the document will exist in the store but won't appear under the instance's document list.IBM_BPM_Document_Propertiesis a special multi-value ECM property that holds your custom metadata as comma-separatedname,valuepairs.
⚠️ Important: All custom properties passed via
documentPropertiesmust be packed into a singleIBM_BPM_Document_PropertiesECMProperty entry usingECMMultiValue. You cannot create oneECMPropertyper custom field — BAW only recognizes oneIBM_BPM_Document_Propertiesentry per document, and adding multiple entries will cause only the last one to be persisted or result in an error. The loop in the script above handles this correctly by collecting all name-value pairs into a singleECMMultiValuebefore assigning it.
Step 2 — Build the Content Stream
Add a second Script task to construct the ECMContentStream object from your base64 input:
tw.local.contentStream = new tw.object.ECMContentStream();
tw.local.contentStream.content = tw.local.content; // base64-encoded string
tw.local.contentStream.mimeType = tw.local.mimeType; // e.g. "application/pdf"
tw.local.contentStream.fileName = tw.local.fileName; // e.g. "invoice.pdf"The content field of ECMContentStream accepts a Base64-encoded UTF-8 string directly — no additional encoding or conversion is needed.
Step 3 — Create the Document via Content Integration Task
Add a Content Integration task to the canvas and configure it as follows:
- Server:
BPM managed store - Operation:
Create document
Input Mapping
documentTitle→tw.local.fileNamecontentStream→tw.local.contentStreamobjectType→"IBM_BPM_Document"properties→tw.local.properties
Output Mapping
objectId→tw.local.documentId
The returned objectId is the unique identifier of the newly created document in the BPM store.
Complete Service Flow
[Start]
↓
[Script: Map Properties]
↓
[Script: Build Content Stream]
↓
[Content Integration: Create Document]
↓
[End]The resulting documentId can be stored as a process variable or returned to the caller for reference.
Key Takeaways
- You don’t need to decode the base64 string manually.
ECMContentStream.contentaccepts it as-is. - The
IBM_BPM_Document_ProcessInstanceIdproperty is what links the document to an instance — don't skip it. - All custom metadata must be packed into a single
IBM_BPM_Document_Propertiesentry usingECMMultiValue— one entry per property will not work. - The entire flow requires no REST calls — it’s fully handled through the Content Integration task and the SYSCM toolkit types.
Have questions or a different approach? Drop a comment below.






