[SalesForce] Trying to update fields in Data Extension with SSJS

I realize this might a very basic question but I am completely new to SSJS so thanks for the understanding.

In Marketing Cloud I am trying run SSJS script in order to update a field in a data extension. Using the available documentation I have put together the following:

<script runat=server language="JavaScript" executioncontexttype="Post" executioncontextname=test>

var TestDE = DataExtension.Init("TEST_DataExtension");
TestDE.Rows.Update({"AccountId":"Test_account"}, ["ContactId"],
["0032405071zljdyAAA"]);

</script>

The syntax seems to be correct and I can run the query via automation studio with no errors but the data extension is not getting updated the way I want it. In other words, field AccountId in TEST_DataExtension is not being changed to "Test_Account" for user with ContactId of 0032405071zljdyAAA.

Any idea why this might be?

Best Answer

Declaration of Server-Side JavaScript Block is incorrect and you have not included the SSJS libraries in your SSJS code.

<script runat=server language="JavaScript" executioncontexttype="get">
Platform.Load("Core","1.1");

var TestDE = DataExtension.Init("TEST_DataExtension");
var result = TestDE.Rows.Update({"AccountId":"Test_account"}, ["ContactId"],["0032405071zljdyAAA"]);

Write('<b>Output:</b>'+result);
</script>

Output: 1

Related Topic