I'm working on a workflow and I would like to be able to read the 'Target Extension' (targetData object) of the workflow on a script that I want to include on the 'Script' tab of a Delivery in the workflow (see img below) Also I would need to have more details about the recipient list fed from the workflow into the delivery.
I can use with no problem the objects targetData and recipient on the body of the delivery itself, but not on this script tab.
Can anyone give a hand please?
Thanks in advance
As with a JS activity in a workflow, it is not possible to get directly the xpath (storage path) of a Query activity in the Delivery script tab.
So you can't use directly targetData object, which is undefined.
logInfo("[WKFxxx] delivery.internalName = " + delivery.internalName)
logInfo("[WKFxxx] delivery.targetData.id= " + delivery.targetData.id)
Hence, you must do a queryDef inside your Delivery script tab, as below (of course, adapt it with your own need, "query" of temp:query beeing the internal name by default of a query activity; and I have added firstName column in the Additional data section of the Query):
var queryTemp = xtk.queryDef.create(
<queryDef schema="temp:query" operation="select">
var res = queryTemp.ExecuteQuery();
logInfo("[WKF345] get the values of temp:query after a Query task execution whose name is query");
logInfo("[WKF345] Count of values = " + res.length());
logWarning("[WKF345] Error in getting the values of temp:query after a Query task execution whose name is query");
logError("[WKF345] Error number: " + e); // or use logWarning if the treatment must go on despite this error
for each(var elt in res)
logInfo("[WKF345] elt.firstName = " + elt.@firstName);
Depending of what you have to do, it is easier to use the <%= targetData.xxxx %> in the delivery body, or you can also do the global queryDef directly in the Delivery script tab (replacing the Query activity box), but to my mind it is
less easier to read and maintain, and duplicate from a workflow to another for other needs; but it is a personal choice of course.
In your specific use case, use rather the easiest way:
Because, in the Delivery script tab, it is more for global treatment, with specific treatment in the for each loop.
But do it in the Delivery script if the test for adding or not the attached file is far more complex than the data of targetData.
(hoping I am enough clear, sorry English is not my native language.)
Thanks so much for your effort Jean-Serge. Both are very good answers.
Thanks very much for your answer Jean-Serge. I'll try your solution as soon as I can.
To give you more information about why using the script tab instead of the body, apart from what you say, is that I need to modify the emali subject line of the delivery depending on the data coming from the workflow, and I don't know how to do that from the delivery itself, as if I try to set the value of delivery.mailParameters.subject I get a 'read only' error. On the other hand, from the script tab it works perfectly.