append multiple string fields and copy the value in a glide list field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2021 04:50 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2021 05:11 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2021 05:24 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2021 05:26 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2021 05:49 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader