- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2018 06:26 AM
Hello,
I'm trying to create a script so I can copy certain values from a table X into a field of type glide_list in another table. Here are the details.
From the table 'resource_plan' I want to retrieve each 'User resource' value and copy it in the field 'Additional assigne' of the corresponding 'Task'.
For example:
Ideally I don't want to push more than once the same User resource in a corresponding Task.
Thank you
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2018 06:16 AM
Hello,
I didn't have time to reply before but I was able to create a script from a couple of posts including some of the ones mentionned here.
Still I was missing the part where the elements pushed in the array had to be copied in a glide list of another table. So here is my final script.
var rpQuery1 = 'u_tache_principale.active=true';
//var rpQuery2 = 'number=prjtask0107247';
var taskList = [];
var taskGR = new GlideRecord(table);
taskGR.addEncodedQuery(rpQuery1);
//taskGR.addEncodedQuery(rpQuery2);
taskGR.query();
gs.print('Task Count: ' + taskGR.getRowCount());
while(taskGR.next()) {
gs.print('Task ID: ' + taskGR.sys_id);
taskList.push(taskGR.sys_id.toString());
}
gs.print('Task List: ' + taskList);
for(var i=0; i<taskList.length; i++ ) {
gs.print('Task ID: ' + taskList[i]);
var userList = [];
var arrayUtil = new ArrayUtil();
var resPlan = new GlideRecord('resource_plan');
resPlan.addQuery('task', taskList[i]);
resPlan.addEncodedQuery('user_resourceNSAMEAStask.assigned_to');
resPlan.query();
gs.print('Count: ' + resPlan.getRowCount());
while(resPlan.next()) {
if(arrayUtil.contains(userList,resPlan.user_resource.sys_id.toString())) {
continue;
}
userList.push(resPlan.user_resource.sys_id);
}
gs.print('User list: ' + userList);
var getTask = new GlideRecord('task');
getTask.get('sys_id', taskList[i]);
gs.print('Task ID: ' + getTask.sys_id);
getTask.additional_assignee_list = userList.join(',');
getTask.update();
}
Thank you all for your time and inputs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2018 12:02 PM
The value of a glide list contain is string of comma separated sys_id's. Therefore you could write a script that loops through all your resource plans and builds up the string and uses the JavaScript indexOf to check that the sys_id isn't already present before adding it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2018 12:16 PM
Hi Sergio,
Following lin may be helpful : How to assign multiple values to a list field
Regards,
Ajay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2018 10:42 PM
you can achieve that by adding few additional lines of code in your script!!
Use array functions like unique,join,indexof !!
by using above three functions you can easily get desired behaviour , for more details on array function supported in servicenow refer the below link.
check the below community thread -for an example:
Thanks,
satheesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2018 12:28 AM
Hello Sergio,
Below code will work for you and i have tried in my personal instance.
//var parentGR = 'd33a0569dbc9e3007301f36f299619c8';
var tested = [];
var incidentGR = new GlideRecord('incident');
//incidentGR.addQuery('rfc',parentGR);
incidentGR.addQuery('parent',current.getUniqueValue());
incidentGR.query();
while(incidentGR.next()){
var caller = incidentGR.caller_id.getDisplayValue();
tested.push(caller);
}
//gs.print('<<inside>>'+tested);
current.work_notes_list = tested;