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.

append multiple string fields and copy the value in a glide list field

SK41
Giga Guru

Hi,

i have  six string fields in a custom table , all have different group names for each record.And i have field of glide list type. I want to add all the group names in the glide list field. The glide list field is referring the custom group table.(u_sec_grp).

The six string fields and glid list type field is on another custom table(u_div). I want to append all the groups in glide list for each record.

How will i achieve that?

PLease help!

Thanks

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use before insert/update BR

Are you having any field within u_div table which refers u_sec_group ?

You can use that to populate the list

Also what user will be giving in the string field?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

yes, glide list type field is referring to u_sec_group table.

glide list type field is on u_div and six other string fields have group name for each record in u_div table. These groups are in u_sec_group table too.

i want update all records through fix script. i want glide list field for each record to get updated with six group names in other string fields.

Hi,

which table records you need to update? u_div ?

If yes then sample script below

Ensure you use valid table names, field names here

updateRecords();

function updateRecords(){

var gr = new GlideRecord('u_div');
gr.query();

while(gr.next()){

var field1 = gr.field1;
var field2 = gr.field2;
var field3 = gr.field3;
var field4 = gr.field4;
var field5 = gr.field5;
var field6 = gr.field6;

var arr = [];

var joinValues = field1 + ',' + field2 + ',' + field3 + ',' + field4 + ',' + field5 + ',' + field6;

var rec = new GlideRecord('u_sec_group');
rec.addQuery('u_name', 'IN', joinValues);
rec.query();
while(rec.next()){
arr.push(rec.getValue('sys_id'));
}

gr.list_field = arr.toString();
gr.setWorkflow(false); // to avoid triggering BR
gr.update();

}

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader