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?
ContactKey and Trigger_Catalog_Items are fields in 'audience for test push', the same I want to make the Upsert.
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");
try {
var triggerCatalogItems = Platform.Variable.GetValue('@triggerRecommendationJson');
var payloadObj = Platform.Function.ParseJSON(triggerCatalogItems);
var numProductsTrigger = payloadObj.length;
var subKey = Platform.Variable.GetValue('@subscriberKey');
if(numProductsTrigger > 0) {
var catalogItem = payloadObj[0]
var productName = catalogItem.name
Platform.Variable.SetValue('@productAvailableCount', numProductsTrigger);
Platform.Variable.SetValue('@productName', productName);
var rows = Platform.Function.UpsertData("audience for test push",["ContactKey"],[subKey],["productName"],[productName]);
}
Write(1);
}
catch(e) {
Write(Stringify(e.message) + Stringify(e.description))
}
</script>
Payload:
[
{
"price":79,
"imageUrl":"image url",
"name":"product name",
"url":"url"
}
]
Thanks