Highlighted
Outstanding Contributor.
Outstanding Contributor.
791 views

HPSM - Problem with for loop

Jump to solution

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;
}
0 Likes
1 Solution

Accepted Solutions
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: HPSM - Problem with for loop

Jump to solution

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);

View solution in original post

0 Likes
4 Replies
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: HPSM - Problem with for loop

Jump to solution

you've got a return in your loop...so it will leave the loop...

Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: HPSM - Problem with for loop

Jump to solution

Hi @dfilipovic2

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'; 
}

 

Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: HPSM - Problem with for loop

Jump to solution

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);

View solution in original post

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: HPSM - Problem with for loop

Jump to solution

Thank you @exeptt 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

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.