- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 01:40 AM
Hi All,
I have 'string' type field on my field. This field holds the value of groups from group table.
Now I have to push these values to a different field type 'list'.
I am trying to pass these values from string field to server side. Glide record group table and get the sys id of all the groups passed and then add to list type. Is this feasible or any other approach?
Note: My main requirement is to add multiple values to assignment group field at same time instead of adding indivisually. Since that was not wroking i am first adding the groups in a new string type field.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2021 05:26 AM
try this in Before BR
(function executeRule(current, previous /*null when async*/ ) {
var groups = current.u_groups; //0f9881b02f612010501d9bacf699b67c , b6a8cd702f612010501d9bacf699b6b1
var arr = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('nameIN'+ current.getValue("u_groups"));
gr.query();
while (gr.next()) {
arr.push(gr.getValue("sys_id"));
}
current.u_assignment_group = arr;
gs.log('test u_assignment_group ' + current.u_assignment_group);
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 01:49 AM
Technically you can query group table with group names, add sys_ids to an array and set the list type field as below:
GlideRecord Object.field_name = Array object.join(",");
But did not get the whole idea as you have both fields on the form. in string field you are updating all the group names with comma separated. and I believe with business rule you will be updating the list type field.
Did not get the user of this.
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2021 10:02 PM
Hi Ahmmed,
My actual requirement is:
I have a field 'assignment group' of type list on my custom table referring to sys_user_group table.
At the moment , values in group field are filtered based on the company of that particular record which is absolutely fine.
In the screenshot shared in my question, for company 'Servicenow' the assignment group is giving me let's say 50 groups that are created for servicenow.
Since the field is of type 'list' it can take multiple values but every time the value will be selected individually.
If i have just 2or3 groups out of 50 to be added here in assignment group it can be done easily.
But if i have to add say 30 groups, so adding manually will be tedious.
If it was list collector it could be easily done.
So i am looking for a way if manual activity can be avoided when many values are to be selected.
Note: i have created the string type field 'groups' as i am not able to directly add multiple groups. So i am trying if i can first add the values in groups and then from groups add it to assignment group.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 04:45 AM
Hello,
Got it. Thank you for details.
Since you will have group names with comma separation, You can query group table with these names, add sys_id of group in a array and then convert array to string and set as assignment group value.
Ex script:
var groups = [];
var grGroup = new GlideRecord("sys_user_group");
grGroup.addEncodedQuery("nameIN" + current.getValue("string_type_group_field_name"));
//add other query is needed
grGroup.query();
while(grGroup.next()){
groups.push(grGroup.getValue("sys_id") + "");
}
//set value to list type field
current.list_field_name = groups.join(",");
above is script if you want to have the script in business rule.
If you want the change to happen at client side form, onchange then create a onchange client script on string type field, call script include and pass group names to script include. in script include you can have similar script as above and pass the sys_ids back to client script and set that value on list type field.
You can refer below link for more details:
https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference/r_ExamplesOfAsynchronousGlideAjax.html
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2021 04:36 AM
Hi Ahmmed,
I tried this...getting an array of sys ids as well but it's not set in list type field 'Assignment group'.
current.u_assignment_group = arr.join(",");
gs.log('test u_assignment_group ' + current.u_assignment_group); //test u_assignment_group 0f9881b02f612010501d9bacf699b67c,b6a8cd702f612010501d9bacf699b6b1
I am setting this using 'After' BR and condition is when group field changes.
Is this because of the type of the field?