Manage seeds through JS
As you aware, we don't have control on computed deliveries hence I am managing seeds through JS Script. The requirement I have is: There are two folders 'ABC-Seeds' and 'XYZ-Seeds', I need to target to complete folder of 'ABC-seeds' and 2 ids of 'XYZ-Seeds' folder, Email IDs are: 'email1' and 'email2'. The JavaScript I am using is as follows:
// query the database to find the winner (best open rate)
var winner = xtk.queryDef.create(
<queryDef schema="nms:delivery" operation="get">
<select>
<node expr="@id"/>
<node expr="@label"/>
<node expr="[@operation-id]"/>
<node expr="[@workflow-id]"/>
<node expr="[scheduling/@contactDate]"/>
<node expr="[output/seedList/where/condition/@expr]"/>
</select>
<where>
<condition expr={"@FCP=0 and @internalName = 'Em123' and @isModel=0"}/>
</where>
<orderBy>
<node expr="[indicators/@estimatedRecipientOpenRatio]" sortDesc="true"/>
</orderBy>
</queryDef>).ExecuteQuery()
// create a new delivery object and initialize it by doing a copy of the winner delivery
var delivery = nms.delivery.create()
delivery.Duplicate("nms:delivery|" + winner.@id)
// append 'winner' to the delivery label
delivery.label = winner.@label + " Test"
delivery.operation_id = winner.@["operation-id"]
delivery.workflow_id = winner.@["workflow-id"]
delivery.output.seedList.humanCond = "Query: folder equal to ABC-Seeds or (folder equal to XYZ-Seeds and email of recipient is included in 'email1,email2')"
delivery.output.seedList.where.displayFilter = "folder equal to ABC-Seeds or (folder equal to XYZ-Seeds and email of recipient is included in 'email1,email2')"
delivery.output.seedList.where.condition.expr= ("[@folder-id] = 9787930 or [@folder-id] = 882531 and [custom_nms_recipient/@email] IN ('email2' , 'email2')")
// save the delivery in database
delivery.save()
// store the new delivery Id in event variables
vars.deliveryId = delivery.id
// Print Log Details
logInfo(vars.deliveryId)
logInfo(delivery.label)
logInfo(winner.output.seedList.where.condition.@expr)
The challanges here I am facing is:
1. The Filtering Condition is taking up as foriegn key of folder id(Below is the screenshot for reference)
2. Everytime it is appending the condition and not replacing the condition with the new computed delivery in Filerting Condition

Please have a look on this and Prompt response will be appreciated.