0

What is the error in this code:

<script runat="server" language="JavaScript" executioncontexttype="get">
    Platform.Load("Core", "1.1");
    try {
        var resident = Attribute.GetValue("_subscriberkey");
        var res;
        res = resident+'-PROMOTIONAL_EMAIL';
        var PrefDE = DataExtension.Init("external key here");
        var value = PrefDE.Rows.Update({preference_value:'False'},['resident_preference_id'], [res]);
    }
    catch(e) {
        Write(Stringify(e));
    }
</script> 

I am getting this error:

There was an error updating the row(s)

There is something wrong in rows.update function Attribute.GetValue is working fine.

9
  • please share the layout of your "PrefDE". Syntax looks fine, it might have to do with the DE. Oct 1, 2021 at 6:47
  • The DE is "Preference_DE", column names are: 1. resident_id 2. preference_value 3. preference_name 4. resident_preference_id(this is primary key combination of resident_id and preference_name). and few more columns.
    – jay
    Oct 1, 2021 at 7:39
  • It's a shared DE
    – jay
    Oct 1, 2021 at 7:42
  • It's a shared DE. If the syntax is correct what could be the problem with DE. I tried this with two different DE's one shared and one normal, but it's not working with both. Lookup function is working fine but rows update not.
    – jay
    Oct 1, 2021 at 7:48
  • 1
    If it is a shared DE, then it is located in Parent BU. Meaning that you have to either perform this operation in Parent, or establish the context otherwise. Oct 1, 2021 at 9:36

1 Answer 1

0

As per your comment, you are attempting to use rows.Update from child BU on a Shared DE. Shared DE location means it is treated like being located in parent.

Your code does not work as you are in the wrong context (child trying to update parent). This can be done though using the "ENT." prefix. (= ENTerprise context)

It's just that the function Rows.Update, which is in the SSJS Core Library, works on the customerkey of the Data Extension, which cannot be prefixed with "ENT.".

Once you use a method that works with the name of the DE - SSJS Platform functions or AMPScript - you can use the ENT.prefix before the data extension name like Platform.Function.UpsertData("ENT.myDE", ...) to do exactly that. It does not help the other way around (from parent to child).

Here is an example with a Shared DE that has one PK (subKey) and one other field, executed successfully on a cloudpage in child BU.

You actually don't need the Platform.Load("Core",1) bit here, as we are not using a Core, but a Platform Function, which works without loading the Core library. I'll include it regardless as your other code might need it.

<script runat="server" type="javascript">
Platform.Load("Core","1");
  try {
      Platform.Function.UpsertDE("ENT.jltest",["subKey"],["777777"],["Email"],["myemail@example.com"])
    
} catch (err) {
    Write(Stringify(err));
  
}
</script>

Whether upsertDE or upsertData is right for your usecase depends. for brevity's sake let's just say upsertDE is for cloudpages, upsertData is for emails.

https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/ssjs_platformDataExtensionUpsertData.htm

https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/ssjs_platformDataExtensionUpdateDE.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.