How to add an assignment group "type" to the Type field?

Laurie Marlowe1
Kilo Sage

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.

find_real_file.png

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

 

 

1 ACCEPTED SOLUTION

Jay81
Tera Guru

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();
}

View solution in original post

8 REPLIES 8

puneetgoels1
Tera Guru

More simpler way is to click on  right click on header hamburger and click update all and then update on the next screen and save itfind_real_file.png

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

 

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();
}

Tim Woodruff
Mega Guru

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: 

find_real_file.png

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.