Manage seeds through JS | Community
Skip to main content
Level 3
March 5, 2019
Solved

Manage seeds through JS

  • March 5, 2019
  • 9 replies
  • 8643 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by geoffreyl240454

Hi mustufam59678037​,

I think that the conditions were not in the winner delivery.

The conditions must be there in the original delivery (winner delivery) when you create the duplicated delivery:

- If yes, the JS code will modifying the values of the duplicated delivery conditions so the provided code will be good.

- If not, the JS code need to be modified in order to create the conditions in the duplicated delivery and not just modifying them.

Many thanks,

Geoffrey.

9 replies

Level 3
March 6, 2019

wodnickiCampaign Classic - QuestionsAdobe Campaign Classic

Hi Team,

This is a bit urgent , please help.

Thanks in advance.

Level 3
March 11, 2019

Hi Team,

Any udpate on this, please?

Level 3
March 19, 2019

Adobe Campaign StandardAdobe Campaign Classic​ @pablo.rosero @Vipul Raghav

Hi Team,

Can anyone from you look into this, its been more than 2 weeks.

Please reply!

pablo_rosero1
Level 9
April 4, 2019

Hi, can anyone give Mustufa a hand with this query?

Jean-Serge Biron

Amit_Kumar

Vipul Raghav

Ananya Kuthiala

geoffreyl240454
Level 3
April 5, 2019

Hello mustufam59678037​,

If I have this conditions on my original delivery (winner delivery in your case):

I can replace the conditions with this JS code:

delivery.output.seedList.where[0].condition[0].boolOperator = 'AND';

delivery.output.seedList.where[0].condition[0].expr = "[custom_nms_recipient/@email] IN ('xyz123@email.com', 'xyz123@ymail.com')";

delivery.output.seedList.where[0].condition[0].condition[0].boolOperator = 'AND';

delivery.output.seedList.where[0].condition[0].condition[0].condition[0].boolOperator = 'OR';

delivery.output.seedList.where[0].condition[0].condition[0].condition[0].expr = '[folder/@id]=9787930';

delivery.output.seedList.where[0].condition[0].condition[0].condition[1].expr = '[folder/@id]=882531';

And my duplicated delivery contains the new conditions:

I hope that helps.

Thanks and Regards,

Geoffrey.

Level 3
April 8, 2019

Hi Geoffrey

geoffreyl24045476, Thank you for your response on this.

I tried the above provided Script, however getting an error saying delivery.output.seedList.where[0] is undefined, below is the screenshot for reference getting in Display Logs.

Here is the complete code I am trying with:

// query the database to find the winner (best open rate)

  var winner = xtk.queryDef.create(

    <queryDef schema="nms:delivery" operation="select">

      <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[0].condition[0].boolOperator = 'AND'; 

  delivery.output.seedList.where[0].condition[0].expr = "[custom_nms_recipient/@email] IN ('xyz123@email.com', 'xyz123@ymail.com')"; 

  delivery.output.seedList.where[0].condition[0].condition[0].boolOperator = 'AND'; 

  delivery.output.seedList.where[0].condition[0].condition[0].condition[0].boolOperator = 'OR'; 

  delivery.output.seedList.where[0].condition[0].condition[0].condition[0].expr = '[folder/@id]=9787930'; 

  delivery.output.seedList.where[0].condition[0].condition[0].condition[1].expr = '[folder/@id]=882531';

  // 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)

Regards,

Mustufa

geoffreyl240454
Level 3
April 8, 2019

Hi mustufam59678037​,

Indeed, please remove the "[0]" from each "where", that should be good without.

Thanks,

Geoffrey.

Level 3
April 8, 2019

Hi geoffreyl24045476,

Thank you for your quick response.

Tested the condition by removing "[0]" from  "where" as well as from "condition", however getting an error saying index out of range.

geoffreyl240454
geoffreyl240454Accepted solution
Level 3
April 8, 2019

Hi mustufam59678037​,

I think that the conditions were not in the winner delivery.

The conditions must be there in the original delivery (winner delivery) when you create the duplicated delivery:

- If yes, the JS code will modifying the values of the duplicated delivery conditions so the provided code will be good.

- If not, the JS code need to be modified in order to create the conditions in the duplicated delivery and not just modifying them.

Many thanks,

Geoffrey.