Skip to main content
5 of 12
added 83 characters in body

Is it possible to create an email activity in JB to Upsert data into a data extension?

I must upsert data into a data extension with SSJS and AMPscript before sending a push notification in a JB. The best approach would be to create a custom activity but it will have to be for the future.

I'm wondering if is possible to create an email to upsert that data extension without it being sent?

I've tried that approach from here with no success, sadly.

This is my script:

%%[
  SET @subscriberKey = AttributeValue('ContactKey')
  /* IS Triggered Products Parse */
  SET @triggerRecommendationJson = AttributeValue('Trigger_Catalog_Items')     
]%%
<script runat="server">
Platform.Load("Core","1");

   var triggerCatalogItems = Platform.Variable.GetValue('@triggerRecommendationJson'); 
   var payloadObj = Platform.Function.ParseJSON(triggerCatalogItems);
   var numProductsTrigger = payloadObj.length;
 
   if(numProductsTrigger > 0) {
     
     var catalogItem = payloadObj[0]
     var productName = catalogItem.name

     Platform.Variable.SetValue('@productAvailableCount', numProductsTrigger);    
     Platform.Variable.SetValue('@productName', productName);     
</script>
     %%[
        SET @upsertData = UpsertData("audience for test push", 1, "ContactKey", @subscriberKey, "productName", @productName)
     ]%%
<script runat="server">
   }
   Write(1)
</script>

Payload:

[
    {
        "price":79,
        "imageUrl":"image url",
        "name":"product name",
        "url":"url"
    }
]

enter image description here

Thanks