Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to get list collector selected values in to "description" field

keerthilatha
Tera Expert

Hi Team,

I have to show record producer-list collector selected values in to "description" field on the table. i have written below code on record producer script cell. please correct me if any wrong here. because it is not working as expected

var myList = g_form.getValue('u_include_all_worker_locations_select_co');

var myArray = myList.split(',');

for (var i = 0; i < myArray.length; i++) {

        var gr = new GlideRecord('core_country');

        if (gr.get(myArray[i])) {

                  // Do what you want to the retrieved record

v_desc += '\nSelected Countries to include :'+ producer.u_include_all_worker_locations_select_co;

        }

}

1 ACCEPTED SOLUTION

Edit :




var myList = producer.u_include_all_worker_locations_select_co.toString();


if(myList !='') {


var myArray = myList.split(',');


var str='';


for (var i = 0; i < myArray.length; i++) {


        var gr = new GlideRecord('core_country');


      if (gr.get(myArray[i])) {


str += 'Selected Countries to include :'+ gr.name ;



        }


}


current.v_desc =str;


}


View solution in original post

21 REPLIES 21

Aakash Shah4
Tera Guru

Can you try like this



use this script on client side to get the display values


var arr=[];


var select_id=$('v_select_box_select_1');


for(i=0; i<select_id.options.length; i++){


//here access the display values by looping through the selected options


arr.push(select_id.options[i].text);


}


alert(arr);


Hi Aakash, its same


it is returning sys id's.


and if i selected 2 values it is showing 2 sys id's in to 2 lines. please see below screen shot.


My Code:


var myList = producer.u_include_all_worker_locations_select_co.toString();


var myArray = myList.split(',');



for (var i = 0; i < myArray.length; i++) {


        var gr = new GlideRecord('core_country');


        if (gr.get(myArray[i])) {


                  // Do what you want to the retrieved record


v_desc += '\nSelected Countries to include :'+ producer.u_include_all_worker_locations_select_co;


        }


}


find_real_file.png


Aakash Shah4
Tera Guru

Mihir Mohanta
Kilo Sage

Try the below script.g_form is not supported here.



var myList = producer.u_include_all_worker_locations_select_co.toString();


var myArray = myList.split(',');



for (var i = 0; i < myArray.length; i++) {


        var gr = new GlideRecord('core_country');


        if (gr.get(myArray[i])) {


                  // Do what you want to the retrieved record


v_desc += '\nSelected Countries to include :'+ producer.u_include_all_worker_locations_select_co;


        }


}