1

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?

1
  • easiest way to debug the script activities is to run it inside a landing page or cloud page. Outside of that, if you are more comfortable in AMPScript, you can have the AMPScript stored in a content area (classic only) and just have the SSJS call this content block. Mar 13, 2017 at 17:10

3 Answers 3

10

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

2
  • Worked like a charm! Thanks a lot. Really appreciate the help Mar 14, 2017 at 16:28
  • 2
    Good to know! Mark my answer if it has solved your problem.
    – Palash Rai
    Mar 14, 2017 at 17:02
3

If you wish to debug SSJS in an Activity, you can use try/catch to grab the error and write it to a data extension:

<script runat = server language = "JavaScript">
Platform.Load("Core", "1.1.1");
try {
    undefinedfunction();
    writeErrorLog("process done");
}
catch (e) {
    var result = e.name + ": " + e.message;
    writeErrorLog(result);
}

function writeErrorLog(msg) {
    var errorLogDE = DataExtension.Init("ENT.errorlog");
    errorLogDE.Rows.Add({message:msg});
}
</script>

I made a shared data extension with a message column of text that I can write to from anywhere in the JavaScript.

0

Try pasting it into a Cloud page or email and see what errors/status you get using Write(YOURVARIABLEHERE). My Guess at first glance is that it may be something to do with the JSON :D Doug

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .