Access to targetData and recipients from Delivery Script

Avatar

Avatar

guillermoL

Avatar

guillermoL

guillermoL

25-08-2017

Hi,

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.

1286112_pastedImage_1.png

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

Guillermo

View Entire Topic

Avatar

Avatar

Jean-Serge_Biro

MVP

Avatar

Jean-Serge_Biro

MVP

Jean-Serge_Biro
MVP

25-08-2017

Olà Guillermo,

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.

Good:

logInfo("[WKFxxx] delivery.internalName = " + delivery.internalName)

Wrong:

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">

      <select>

        <node expr="@firstName"/>

      </select>

      <where>

      </where>

    </queryDef>)

try

{

  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());

}

catch(e)

{

  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.

Regards
Jean-Serge