DOCX document creation
Guide to Creating a Print Template from a DOCX Document
This procedure outlines how to generate DOCX documents in Team assistant (TAS) based on a pre-prepared Word template. The necessary data from a task in TAS will be automatically filled into the template.
Use Cases
- Generating a submission log based on sent mail within a company.
- Creating a document signing sheet generated from an approval matrix for a process.
- Producing a contract based on selected attributes in TAS.
Preparing the Document Template
Create a Word document with fixed content, such as headers, footers, and general structure. Use special tags to mark where data from TAS should be inserted. These tags use triple plus signs (+++
) to open and close. The variable name, defined in TAS calculations, is placed between the tags.
+++companyName+++
Example:
📄 Download document - DOCX_document_creation-template.docx
Bulleted Lists in the Template
Define a list variable in TAS and iterate over it using
Word Template:
+++FOR myBullet IN myBullets+++
• +++= $myBullet+++
+++END-FOR myBullet+++
TAS Calculation:
const myBullets = vars['list'].getValue();
Images in the Template
To insert images dynamically:
Word Template:
+++IMAGE workerSignature()+++
TAS Calculation:
const workerSignatureBase64 = workerSignatureFileName ? lib.getFileContents(`${signaturesAndStampsPath}/${workerSignatureFileName}`, 'base64') : '';
let generated = docx.docxTemplater({
template,
data: docxData,
processLineBreaksAsNewText: true,
additionalJsContext: {
workerSignature: func => {
let data = workerSignatureBase64;
return {
width: signatureWidth,
height: signatureHeight,
data,
extension: '.png'
};
}
}
});
Dynamic Tables
This structure iterates over each row in the table, inserting appropriate values into the columns.
Word Template:
Index | Code | Name |
+++ FOR row in typeOfCost+++ |
|
|
+++= $row.DTV_INDEX+++ | +++= $row.COL_1+++ | +++= $row.COL_2+++ |
+++END-FOR row+++ |
|
|
TAS Calculation:
const myTable = vars['table'].getValue();
Creating Dynamic Rows
This iterates through each row, inserting relevant values into the table.
Word Template:
Order name | Price |
+++FOR index in Array.from(Array(items.itemName.length).keys())+++ |
|
+++= items.itemName[$index] +++ | +++= items. unitPrice[$index] +++USD |
+++END-FOR index+++ |
|
TAS Calculation:
const myDynamicRows = vars['dynRows'].getValue();
Uploading the Template to TAS
- Navigate to the "Documents" tab in TAS.
- Click "Upload File" and select your prepared Word document.
- Locate the uploaded document using the filters in "Documents" > "All".
- Open the browser console (press F12).
- Go to the "Network" tab and filter for the uploaded document.
- Copy the response value after
"DMS:"
Example Path:
DMS:_7d5/template-podaciArch.docx.7d5fd45a805c10856ed4b07b9ce9048b.1.1655895144727
- Insert the copied file path into the task where the DOCX should be generated:
const template = lib.getFileContents('/srv/dms-data/neworigin/storage/_7d5/template-podaciArch.docx.7d5fd45a805c10856ed4b07b9ce9048b.1.1655895144727', 'buffer');
Generating the DOCX Document
Within the specific task where the document will be generated:
- Define variables in the calculation:
const companyName = vars['companyName'].getValue();
const date = moment(vars['today'].getValue()).format('MMMM D, YYYY');
const items = vars['itemsDR'].getJSON();
const itemsDT = JSON.parse(vars['itemsDT'].IVAR_MULTI_SELECTED);
const internalCaseNr = vars['internalCaseNr'].getValue();
const typeOfCost = dt.from("001-typeOfCost").get(); - Define the document template path:
const template = lib.getFileContents('/srv/dms-data/neworigin/storage/_7d5/template-podaciArch.docx.7d5fd45a805c10856ed4b07b9ce9048b.1.1655895144727', 'binary');
- Generate the document using TAS's templating function:
const generated = docx.docxTemplater({
template,
data: {
companyName,
date,
items,
itemsDT,
internalCaseNr,
typeOfCost
}
}); - Save the generated document:
lib.storeAttachment('template_generated.docx', generated, false);
This process will generate a document based on the template and insert the appropriate values.
Generate to PDF
This process will generate a document based on the template and insert the appropriate values.
const templateGenerated = 'template_generated.docx';
lib.storeAttachment(templateGenerated, generated, false); vars['attachmentToSend'].setValue(templateGenerated); lib.libreConvertDmsFile(vars['attachmentToSend']); vars['attachmentToSend'].setValue('template_generated' + '.pdf');
Updated
by Anna Gernát