1

Anybody an idea what is wrong with this script? It is my first SSJS script in the automation studio but I just get the error message: An error has occured. I got the functions from the documentary. https://developer.salesforce.com/docs/atlas.en-us.mc-programmatic-content.meta/mc-programmatic-content/ssjs_platformDataExtensionLookupOrderedRows.htm

Best regards, Alex

<script runat="server">
Platform.Load("Core","1.2");
 var leadRows = Platform.Function.LookupOrderedRows('Search Agent','Lead:Id,Lead:Sa_City','Lead:Id DESC',['Lead:Status','Lead:lead_Source_comment__c'],['Prospect','City Not Covered']);
 if (leadRows && dataRows.length > 0) {
      for(var i=0; i<dataRows.length; i++) {
        var lead_id = leadRows[i]['Lead:Id'];
        var city = leadRows[i]['Lead:SA_City'];
        var apartmentRows = Platform.Function.LookupOrderedRows('Apartment__c_Salesforce','Id','Id DESC','Id',city);
        var numberOfApartments = apartmentRows.length;
        var numberOfRowsAffected = Platform.Function.UpdateDE('Search Agent',['Lead:Id'],[lead_id],['Online_AND_Verified_AND_Published_ApartmentsInTheCity'],[numberOfApartments]);
      }
 }
</script>
1
  • So the middle part looks now like this: .... if (leadRows && leadRows.length > 0) { for(var i=0; i < leadRows.length; i++) { ... Has somebody else an idea why this is not working? – Alexander Schmelzer Oct 17 '18 at 8:24
2

I know this is 2 years old, but I think the issue is the first line: Platform.Load("Core","1.2"); There is no 1.2 as far as I'm aware, try with 1.1.

Also, I can never get the LookupOrderedRows to function with the column names in the second column (as stated in the Marketing Cloud documentation). So the following never works:

var dataRows = Platform.Function.LookupOrderedRows('DE','NAme of Column to return', 'OrderCol DESC/ASC', 'Col to match on', 'Match Value');

But this does:

var dataRows = Platform.Function.LookupOrderedRows('DE', number of cols to return, 'OrderCol DESC/ASC', 'Col to match on', 'Match Value');

This aligns to the AMPscript LookupOrderedRows function

-1

You should modify the if statement and the for, as follows:

if (leadRows && leadRows.length > 0) {
      for(var i=0; i<leadRows.length; i++)
2
  • Welcome to SFSE! This answer would be better if you were to go into detail about why this resolves the problem. It may be obvious to you, but being explicit and thorough should help OP (Original Poster of the question), and perhaps others with similar problems, learn from their mistake. – Derek F Oct 16 '18 at 23:34
  • Hey Derek, thanks for your response! Unfortunately, after changing it, the error still remains. – Alexander Schmelzer Oct 17 '18 at 8:22

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.