HPSM - Problem with for loop

Hello experts,

I have created Array of char into "device" table that is named shareholder.contacts but I am having problem with looping throught that Array when I want to return that data.

I am creating Rule Set with HTML Template that uses JavaScript to select data about persons, data stored into Array is form of "Contact Name" and there is Match Field, Match Data for that Array with Contacts table.

Problem with this function that I created is that it only loops once in for loop even that it has Array length of 3, do you know why and how can I solve this problem?

This is code snippet from that function

function getShareholders(RECORD)
{
var fShareholder = new SCFile("device");
var rc = fShareholder.doSelect("logical.name=\"" RECORD "\"");
if (rc == RC_SUCCESS)
{
print(fShareholder.shareholder_contacts.length());
for(var i=0;i<fShareholder.shareholder_contacts.length();i )
  {
print(fShareholder.shareholder_contacts[i]);
return fShareholder.shareholder_contacts[i];
}
}
return null;
}
  • you've got a return in your loop...so it will leave the loop...

  • Hi 

    Return will stop executing fuction . 

    try code bellow 

    function getShareholders(RECORD) {
    var fShareholder = new SCFile("device");
    var retVal = [];
    if (fShareholder.doSelect("logical.name=\""   RECORD   "\"") == RC_SUCCESS) { 
      print(system.functions.lng(fShareholder.shareholder_contacts);
      for(var i=0, lng = system.functions.lng(fShareholder.shareholder_contacts);i<lng;i  )  {
        print(fShareholder.shareholder_contacts[i]);
        retVal.push(fShareholder.shareholder_contacts[i]);
      }
    return retVal;
    }
    return 'no contacts found'; 
    }

     

  • Verified Answer

    Thanks, I have come to that conculsuon with printing. I have tried for each function but it didn't work. I have solved the problem like this:

    function getShareholders(RECORD)
    {
    var fShareholder = new SCFile("device");
    var rc = fShareholder.doSelect("logical.name=\"" RECORD "\"");
    if (rc == RC_SUCCESS)
    {
    var shareholders = new Array()
    var shareholders = fShareholder.shareholder_contacts;
    return shareholders;
    }
    return null;
    }
     
    Then calling it in Process Designer - Rule Set - Send HTML template:
    var users=system.library.cpg.getShareholders(vars.$L_file.affected_item);
  • Thank you this will push every single record out and then return it.

    That is what I needed, I have tried to do it with For-Each function but it didn't work...

    Best regards,

    Dino