Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Set the assignment group base on UI action

Admin Pro
Tera Contributor

I am trying to update the assignment group filed on the incident form when user click on a UI action button. The button will only appear if the incident state is not set to close and user has a specific role. By clicking on the button following should happen;
Incident state sets to close , which it does
Assignment group sets to "Help Desk" regardless of what it was already populate it with. which it does work at the time. I have used the following methods, but non of them have worked so far.

current.incident_state = 7;
current.assignment_group.setDisplayValue("Help Desk");
if(current.isValidRecord()) {
// this is when close is called as an update, just update it
current.update();
} else {
// and insert the record
current.insert();
}
current.assignment_group = current.assignment_group.setDisplayValue("Help Desk");
current.assignment_group = GetIDValue('sys_user_group', 'Help Desk');

Any idea why this is not working, or have anybody done this before?!

I appreciate any commend or feedback.

6 REPLIES 6

Not applicable

I think you want the


.getDisplayValue()
method not

.setDisplayValue()


narinder_guru
Kilo Contributor

I have a similar issue to this and i dont know why my script is not working ;-(. I have an accept button which autofills the assignee to the user logged in but also should autofill the assignment group which that user belongs too. This is my script below i used in the UI action
current.assigned_to = gs.getUserID()
var assign = g_form.getValue('assigned_to');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', assign);
gr.query();
gr.next();
current.assignment_group = current.assignment_group.setDisplayValue(gr.group);

Please help, the customer has been complaining to get this working.
Your help is much appreciated.

Thanks



problem with the 2nd one is the user could be a member of many groups, how does the system know which one to choose?
best bet in my opinion is to create a primary group field on the users record, populate that and then query for that from the user record.

Marc


Jay_Ford
Kilo Guru

All you need to do is provide your script with the sys_id of the group you wish to assign it to.



current.assignment_group.setDisplayValue("d625dccec0a8016700a222a0f7900d06");
if(current.isValidRecord()) {
// this is when close is called as an update, just update it
current.update();
} else {
// and insert the record
current.insert();
}