[SalesForce] Trying to InsertData or UpsertData using SSJS and I getting error message “Unable to retrieve security descriptor for this frame.”

I'm working on a custom Subscription Management page using CloudPages, and I'm able to update existing subscriptions in the target data extension using SSJS just fine:

var updateResults = Platform.Function.UpdateData(data_extension, ["Market", "Department_Name", "Campaign_Name"], [market, department, campaign_name], ["LastSetBy", "Subscription_Status", "AsOfDate"], ["Custom Unsub", status, Now()]);

But this doesn't work given the nature of these subscriptions (opt-out for our customers) I need to be able to insert new records, and this is the code I'm trying to use:

var upsertResults = Platform.Function.UpsertData(data_extension, 4, "Market", market, "Department_Name", department, "EmailAddress", emailAddress, "Campaign_Name", campaign_name, "ClientID", client_id, "LastSetBy", "Custom Unsub", "Subscription_Status", status, "AsOfDate", Now());

It gives me an error message:

Unable to retrieve security descriptor for this frame.

I also tried a direct InsertData, but this doesn't work:

var insertResults = Platform.Function.InsertData(data_extension, "Market", market, "Department_Name", department, "EmailAddress", emailAddress, "Campaign_Name", campaign_name, "ClientID", client_id, "LastSetBy", "Custom Unsub", "Subscription_Status", status, "AsOfDate", Now());

It gives me the same error message.

Best Answer

You're writing it like AMPScript, and SSJS UPSERT is different syntax. Which is why the Update works (correct syntax) but the UPSERT and INSERT don't.

For example, below is a valid UPSERT:

<script runat="server">
     var rows = Platform.Function.UpsertData("CustomerData",["ID"],["12345"],["Company","Country","Region"],["exampleCompany","USA","West"]);
</script>

It goes like this:

Platform.Function.UpsertData( deName, ["whereClauseColumn1", "whereClauseColumn2"], ["whereClauseValue1","whereClauseValue2"], ["upsertColumn1", "upsertColumn2"], ["upsertValue1","upsertValue2"])

Related Topic