0

I am trying to use SSJS to retrieve the DE names of all DE's in a particular folder (folderid = 14273, not sure if that needs to be in quotations), and save them in an upsert DE (DE name = Dede). The below script runs successfully in automation studio but when I check back Dede, no rows are generated. I also tried testing by hardcoding the name of just 1 DE in the folder but that didn't work either.

The upsert DE has 2 fields, Name (primary key, text, max 300 characters) and CreatedDate (date, nullable)

<script runat="server">
   Platform.Load("Core", "1.1.1");
   var folderId = "14273";  
   var targetDEName = "Dede";  
   var dataExtensions = Platform.Function.DataExtension.Retrieve({Property:"CategoryID", SimpleOperator:"equals", Value:folderId});

   for (var i = 0; i < dataExtensions.length; i++) {
       var deName = dataExtensions[i].Name;  
       
       var rowsAffected = Platform.Function.UpsertData(
           targetDEName,                  
           ['Name'],                       
           [deName],                      
           ['CreatedDate'],               
           [null]                         
       );
   }
</script>

1 Answer 1

0

Everything wrapped in a try / catch runs successfully in automation studio , so well-intentioned as it may be, you are actually actively obfuscating what is going wrong with your try/catch.

In your

} catch (error) {
   // log to a DE
   // , Write(Stringify(error)) to print to cloudpage
   //, throw(error) to trigger automation fail...
}

...you should do SOMETHING that helps you identify the error, i.e. print the error out (for this, test via a published cloudpage (preview fails) >> automation studio cannot "write" anywhere, if you want to test in automation studio, you would need to log to a DE - and thats whats failing...,)

For your actual problem, suggestion - use the way easier Platform.Function.UpsertData

make sure you get the arrays right as seen below (note: order is different from AMPScript), and it should be quite straightforward from there.

var updatedRowCount = Platform.Function.UpsertData(
    "nameOfYourDE"
    ,['pkField1','pkField1'] // list of primary key field names
    ,['pkValue1','pkValue2'] // list of primary key field values
    ,['field3', 'field4'] // list of non primary key field names
    ,['value3', 'value4'] // list of non primary key field values
);         
3
  • Thank you for your answer. I have tried updating the code (updated in my original post) but it is still failing with this error in automation studio - Error: A runtime error occurred while the SSJS Activity executed the SSJS script. Please review the SSJS activity to ensure that errors are handled properly.
    – houjicha
    Commented Oct 24 at 14:09
  • That is why I recommend to test via a cloudpage. Commented Oct 24 at 15:08
  • Ok, it's working now. Testing on the cloudpage revealed that no DE's were actually being found, and for some reason inputting the categoryId directly like this solved the error. var dataExtensions = DataExtension.Retrieve({ Property: "CategoryID", SimpleOperator: "equals", Value: "14273" });
    – houjicha
    Commented Oct 25 at 6:58

You must log in to answer this question.

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