0

We are adding below code to check if Data extension is present or someone has deleted accidently , as we are fetching content ( with only one row) from DE to display on a cloudpage if someone delete it accidently there should not be 500 error , so we implemented try and catch in SSJS.

But also we need to make sure if someone clears Data from DE accidnetly then also that should capture in Try block , we tried but without any success below is the code

   <script runat=server language="JavaScript">

   var HeaderDE , HeaderDECheckRowCount ;
   HeaderDE = "DataExtension_Name";

try {
      HeaderDE = Platform.Function.LookupRows(HeaderDE,'Id','1'); /* to check DE is exist or not */ - working fine 
      HeaderDECheckRowCount = Platform.Function.rowcount(HeaderDE); /* to check DE has at least one row */  - not working 
 
if (HeaderD > 0)
 {
      HeaderDEExist = true;
 }
 else
 {
   HeaderDEExist = false;
 }
    }
catch (e) 
    {
       HeaderDEExist = false;
    }

Platform.Variable.SetValue("@HeaderDEExist",HeaderDEExist);

</script>

We are able to check and handle if we delete DE but not able to catch if someone clear data from DE , DE has only one row

2 Answers 2

1

Check the Platform.Function.LookupRows documentation for an example of how to emulate a rowcount:

https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformDataExtensionLookupRows.html

Essentially you just look at the result of Platform.Function.LookupRows like the array that it is, and count its elements (= you count rows).

<script runat="server">
     var dataRows = Platform.Function.LookupRows('CustomerData',['FirstName','LastName'],['Angela','Cruz']);
     if(dataRows && dataRows.length > 0) {
          for(var i=0; i<dataRows.length; i++) {
               Platform.Response.Write(dataRows[i]["Email"]);
          }
     }
</script>

Your specific example can of course get rid of the for loop:

<script runat="server">
     var dataRows = Platform.Function.LookupRows('CustomerData',['FirstName','LastName'],['Angela','Cruz']);
     if(dataRows && dataRows.length > 0) {
          /* check for at least one record was successful, perform rest of code */
     }
</script>
0

Referring to the SF page, I am afraid there is no such rowcount platform function (Platform.Function.rowcount).

You will likely need to do a Rows.Retrieve and get the length of the result array. This may help.

You must log in to answer this question.

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