List to array

Woz
Tera Contributor

Hello,

 

I am trying to run this script on a business rule on the std_change_proposal table but nothing is being returned in the while loop.

(function executeRule(current, previous /*null when async*/) {
    
    //u_m2m_std2chg
    
    var chgs = [];
    
    chgs = current.change_requests.toString();
    
    chgs = chgs.split(',');
    
    while(chgs.next()){
        gs.info(chgs.getDisplayValue());
        
    }
    
    

})(current, previous);

 

I am trying read from the list in Sample Change requests

 

find_real_file.png

1 ACCEPTED SOLUTION

Sagar Patro
Kilo Guru

Hey,

Not sure if you are trying to get the Change numbers or Sys IDs of them. So,

 

If you need Sys_ids then, use below

 

(function executeRule(current, previous /*null when async*/) {
    
 
    // no need of this. You may remove it. var chgs = [];
    
    var chgs = current.change_requests.toString();
    
    chgs = chgs.split(',');
    
    var i=0;//Decalre a loop variable

    while(i<chgs.next()){

        gs.info(chgs[i]);//Print sys_id of the change
        i++;

    }
    
    

})(current, previous);

 

OR

if you need change numbers then, use the below

 

(function executeRule(current, previous /*null when async*/) {
    
 
    // no need of this. You may remove it. var chgs = [];
    
    var chgs = current.getDisplayValue("change_requests");//Update the code here
    
    chgs = chgs.split(',');
    
    var i=0;//Decalre a loop variable

    while(i<chgs.next()){

        gs.info(chgs[i]);//Prints Change numbers
        i++;

    }
    
    

})(current, previous);

 

Good Luck!

Mark this as Correct and useful if it was.

View solution in original post

3 REPLIES 3

Upender Kumar
Mega Sage

Hi 

use below

var chgs = [];
    
    chgs = current.change_requests.toString();
    
    chgs = chgs.split(',');
    
    for(var i=0;i<chgs.length;i++){
        gs.info(chgs[i]);
        
    }

thanks

Sagar Patro
Kilo Guru

Hey,

Not sure if you are trying to get the Change numbers or Sys IDs of them. So,

 

If you need Sys_ids then, use below

 

(function executeRule(current, previous /*null when async*/) {
    
 
    // no need of this. You may remove it. var chgs = [];
    
    var chgs = current.change_requests.toString();
    
    chgs = chgs.split(',');
    
    var i=0;//Decalre a loop variable

    while(i<chgs.next()){

        gs.info(chgs[i]);//Print sys_id of the change
        i++;

    }
    
    

})(current, previous);

 

OR

if you need change numbers then, use the below

 

(function executeRule(current, previous /*null when async*/) {
    
 
    // no need of this. You may remove it. var chgs = [];
    
    var chgs = current.getDisplayValue("change_requests");//Update the code here
    
    chgs = chgs.split(',');
    
    var i=0;//Decalre a loop variable

    while(i<chgs.next()){

        gs.info(chgs[i]);//Prints Change numbers
        i++;

    }
    
    

})(current, previous);

 

Good Luck!

Mark this as Correct and useful if it was.

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


Use below Script:

 

(function executeRule(current, previous /*null when async*/) {
    
    //u_m2m_std2chg
    
    var chgs = [];
    
    chgs = current.change_requests.getDisplayValue().toString(); // Hope change_request is a field name of the Sample Change Request.
    
    chgs = chgs.split(',');
    
    for(var i =0; i<chgs.length;i++)
{
       gs.log(chgs[i]);
    }
    
    

})(current, previous);

Thanks,

Ashutosh Munot