- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 07:40 AM
Hello,
I am trying to write a script to add a "Type" to all our assignment groups. I want to add the "Westar" type to the Type field for all existing assignment groups.
I'm not sure how to code to add the "Westar" type into the List Collector:
var t = new GlideRecord('sys_user_group');
t.setLimit(1);
t.addQuery('u_assignment_group', true);
t.query();
while(t.next()){
t.type = 'Westar';
gs.print(t.number);
}
Thank you in advance!
Laurie
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 09:27 AM
Please try below script.
var grp = new GlideRecord('sys_user_group');
grp.query();
while(grp.next())
{
grp.type = grp.type + ",1cb8ab9bff500200158bffffffffff62"; // replace with Westar sys_id
grp.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 07:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 07:53 AM
The only issue with doing it that way is it wipes out any existing entries. I need to add "Westar" to what is already in the list collector.
Thanks,
Laurie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 08:32 AM
Ok. Here is the solution then. Replace 74af88c6c611227d0066386e74dc853d with sys id of Westar and you will be good to go
var t = new GlideRecord('sys_user_group');
t.addQuery('active', 'true');
t.query();
while(t.next()){
t.type = t.type + ',74af88c6c611227d0066386e74dc853d';
t.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 07:59 AM
I don't understand what you're trying to do.
Do you want to add a new value to the type field on the sys_user_group table? Or are you trying to add a new option to a variable on a catalog item?
In both cases, you don't need a script to do this. You can simply add an option to the field.
If for some reason, you need to set the field value using a client script, you can do so using the g_form API:
g_form.setValue('field_name', 'comma,separated,values', ['array', 'of', 'display values']);
On Slack, I recently explained some concepts about the field type you seem to be using and how to interact with it using the g_form API and populating the display values for better performance:
If you want to append a value to the field, you can do so by simply concatenating what already exists in the field with the new value:
var formValue = g_form.getValue('field_name');
g_form.setValue('field_name', (formValue + ',new_value'));
You can do a similar thing on the server to append the new value to the field's value, replcing g_form with your GlideRecord object.