In the postprocess of my datamapper I look at each record to determine if I have to create any pdfs at all for my current job. The answer (yes/no, true/false) should be used in a condition in my workflow. But I cannot figure out how to get the information from the datamapper to the workflow.
First I thought local parameters where the answer but those only seem to work in the other direction.
Metadata only seems to work if I put the needed information in each record and then all the data in the metadata - which seems overkill.
Any other way to get a simple boolean from datamapper to workflow would be appreciated.
@Tobias, can you let us know please based on what condition you determine if you have to create any PDF documents? Can you perhaps share your Postprocessor Script?
[Edit: Changed Postpagination Script to Postprocessor Script]
@Marten the workflow is for sending emails. in a first branch i create the “Optimize for fast web view” attached pdfs. whether any pdf is needed, will be determined for each record in the datamapper (very long script that checks a lot of data and composes a list of all the nedded attachments for an email. the script in the postpagination just checks, if there are any attachments at all for the whole job. my last try:
if (automation.parameters.isPdfAttachmentCreation === 'PdfAttachmentCreation') {
var lcHasAttachment = "false"; //Parameter is a string
var recordLength = data.records.length;
for (var i=0; i < recordLength;i++){
if (data.records[i].fields.Attachments != "") {
lcHasAttachment = "true";
break;
}
}
//automation.parameters.hasAttachments = lcHasAttachment;
}
A possible solution is to apply the following steps:
Add the Local Variables hasAttachments and docCount to the Workflow process which contains the Execute Data Mapping Workflow plugin has been applied
Select Metadata as Output Type in the Properties window of the Execute Data Mapping Workflow plugin
Add a Branch to the Workflow process and place it directly after the Execute Data Mapping Workflow plugin
Add a Metadata Filter Workflow plugin to the Branch and apply the rule* (_vger_fld_Attachments Not equal ) on the Document filter level
Add a Set Job Infos and Variables Workflow plugin to the Branch, place it after the Metadata Filter Workflow plugin and select the Local Variable %{docCount} under Var/Info# and insert the value GetMeta(SelectedDocumentCount[0], 11, Job) under Value (in the same row)
Add a Run Script Workflow plugin to the Branch, place it after the Metadata Filter Workflow plugin, change the selected Language option to JScript and apply the following JavaScript code to it:
var docCount = Watch.GetVariable("docCount");
if (isNaN(docCount)) {
Watch.Log("Error: 'docCount' is not a number", 1);
} else {
var hasAttachments = parseInt(docCount) > 0;
Watch.SetVariable("hasAttachments", hasAttachments);
}
Please note that the following line of JavaScript code:
var hasAttachments = parseInt(docCount) > 0;
Can also be replaced with:
var hasAttachments = false;
if (parseInt(docCount) > 0) {
hasAttachments = true;
}
As a result you can use the value assigned to the Local Variable hasAttachments on another place of your Workflow process. Just make sure that you aren’t using it before executing the above Workflow plugin.
*After Not equal follows nothing as we are checking for an empty value.
For future considerations: If I have workflow conditions depending on the data, I will have to learn how to use metadata because there is no (easy) build-in way to get a boolean back from datamapper to workflow, right?
However, I have added that feature as an improvement request for our R&D to look at. I can’t promise anything, but it may eventually make its way into the software.