Hi @Humanit,
You are absolutely right. You can use workflows to render the contract, based on the values recorded in the modules.
I recommend the following approach when creating the workflow:
- create template variables based on the module records.
This can be achieved by an expression in workflows
eg:
{
"pdf_title":pdf_title,
"pdf_content":pdf_content,
}
### 2. render the pdf template
*This can be achieved by a workflow function/render template*
_Note: make sure to add `.pdf` suffix when defining the `documentName`. ie: `my test.pdf`_
_Note: make sure to use mime type `application/pdf` when defining the `documentType`_
Example workflow
This example workflow prompts for a title, content and email to render a pdf, attach the rendered PDF to an email and send the email to the entered email address
{
"workflows": [
{
"handle": "cjt_pdf_templates",
"enabled": true,
"meta": {
"name": "CJ - Test generating pdf with templates",
"description": "Testing for generation of PDF rendered with templates",
"visual": null
},
"keepSessions": 0,
"steps": [
{
"stepID": "4",
"kind": "prompt",
"ref": "input",
"arguments": [
{
"target": "title",
"value": "PDF Title",
"type": "String"
},
{
"target": "message",
"value": "Enter title for the document",
"type": "String"
},
{
"target": "type",
"value": "text",
"type": "String"
}
],
"results": [
{
"target": "pdf_title",
"expr": "value"
}
],
"meta": {
"name": "",
"description": "",
"visual": {
"id": "4",
"parent": "1",
"value": "Enter PDF title",
"xywh": [
2272,
1912,
200,
80
]
}
}
},
{
"stepID": "6",
"kind": "prompt",
"ref": "input",
"arguments": [
{
"target": "title",
"value": "PDF Content",
"type": "String"
},
{
"target": "message",
"value": "Enter content for the document",
"type": "String"
},
{
"target": "type",
"value": "text",
"type": "String"
}
],
"results": [
{
"target": "pdf_content",
"expr": "value"
}
],
"meta": {
"name": "",
"description": "",
"visual": {
"id": "6",
"parent": "1",
"value": "Enter PDF Content",
"xywh": [
2272,
2032,
200,
80
]
}
}
},
{
"stepID": "8",
"kind": "function",
"ref": "templatesRender",
"arguments": [
{
"target": "lookup",
"value": "cjt_test_pdf",
"type": "Handle"
},
{
"target": "documentName",
"value": "corteza test.pdf",
"type": "String"
},
{
"target": "documentType",
"value": "application/pdf",
"type": "String"
},
{
"target": "variables",
"expr": "{\n \"pdf_title\":pdf_title,\n \"pdf_content\":pdf_content,\n}",
"type": "Vars"
}
],
"results": [
{
"target": "rendered_pdf",
"expr": "document"
}
],
"meta": {
"name": "",
"description": "",
"visual": {
"id": "8",
"parent": "1",
"value": "Render PDF",
"xywh": [
2816,
2168,
200,
80
]
}
}
},
{
"stepID": "10",
"kind": "prompt",
"ref": "input",
"arguments": [
{
"target": "title",
"value": "Your email",
"type": "String"
},
{
"target": "message",
"value": "Please enter the email address, to receive the generated PDF",
"type": "String"
},
{
"target": "type",
"value": "email",
"type": "String"
}
],
"results": [
{
"target": "email",
"expr": "value"
}
],
"meta": {
"name": "",
"description": "",
"visual": {
"id": "10",
"parent": "1",
"value": "Enter email",
"xywh": [
2272,
2160,
200,
80
]
}
}
},
{
"stepID": "12",
"kind": "function",
"ref": "emailMessage",
"arguments": [
{
"target": "subject",
"value": "Generated PDF",
"type": "String"
},
{
"target": "to",
"expr": "email",
"type": "String"
},
{
"target": "plain",
"value": "Here's your PDF generated with Corteza Templates",
"type": "String"
}
],
"results": [
{
"target": "base_email",
"expr": "message"
}
],
"meta": {
"name": "",
"description": "",
"visual": {
"id": "12",
"parent": "1",
"value": "Build base email",
"xywh": [
2536,
2160,
200,
80
]
}
}
},
{
"stepID": "15",
"kind": "function",
"ref": "emailAttach",
"arguments": [
{
"target": "message",
"expr": "base_email",
"type": "EmailMessage"
},
{
"target": "content",
"expr": "rendered_pdf.document",
"type": "Reader"
},
{
"target": "name",
"value": "rendered_pdf.pdf",
"type": "String"
}
],
"results": [],
"meta": {
"name": "",
"description": "",
"visual": {
"id": "15",
"parent": "1",
"value": "Attach pdf",
"xywh": [
2536,
2304,
200,
80
]
}
}
},
{
"stepID": "17",
"kind": "function",
"ref": "emailSendMessage",
"arguments": [
{
"target": "message",
"expr": "base_email",
"type": "EmailMessage"
}
],
"results": [],
"meta": {
"name": "",
"description": "",
"visual": {
"id": "17",
"parent": "1",
"value": "Send email",
"xywh": [
2544,
2440,
200,
80
]
}
}
}
],
"paths": [
{
"parentID": "4",
"childID": "6",
"meta": {
"name": "",
"description": "",
"visual": {
"id": "7",
"parent": "1",
"points": [],
"style": "exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;",
"value": null
}
}
},
{
"parentID": "6",
"childID": "10",
"meta": {
"name": "",
"description": "",
"visual": {
"id": "11",
"parent": "1",
"points": [],
"style": "exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;",
"value": null
}
}
},
{
"parentID": "10",
"childID": "12",
"meta": {
"name": "",
"description": "",
"visual": {
"id": "13",
"parent": "1",
"points": [],
"style": "exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;",
"value": null
}
}
},
{
"parentID": "12",
"childID": "8",
"meta": {
"name": "",
"description": "",
"visual": {
"id": "14",
"parent": "1",
"points": [],
"style": "exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;",
"value": null
}
}
},
{
"parentID": "8",
"childID": "15",
"meta": {
"name": "",
"description": "",
"visual": {
"id": "16",
"parent": "1",
"points": [],
"style": "exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;",
"value": null
}
}
},
{
"parentID": "15",
"childID": "17",
"meta": {
"name": "",
"description": "",
"visual": {
"id": "18",
"parent": "1",
"points": [],
"style": "exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;",
"value": null
}
}
}
],
"triggers": [
{
"resourceType": "system",
"eventType": "onManual",
"constraints": [
{
"name": "",
"op": "=",
"values": [
""
]
}
],
"enabled": true,
"stepID": "4",
"meta": {
"description": "",
"visual": {
"edges": [
{
"childID": "4",
"meta": {
"description": "",
"label": "",
"visual": {
"id": "5",
"parent": "1",
"points": [],
"style": "exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;",
"value": null
}
},
"parentID": "3"
}
],
"id": "3",
"parent": "1",
"value": "on manual",
"xywh": [
2016,
1912,
200,
80
]
}
}
}
]
}
]
}
Example Template
This template uses the variables to interpolate values received from the workflow function for rendering
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Test PDF with Corteza</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
<h2>Test pdf template</h2>
<h4>Test title: {{.pdf_title}} </h4>
<hr>
<h4>Test content:</h4>
<p>{{.pdf_content}}</p>
</body>
</html>
Hope the above example helps
.