Assign to me UI action help

Sam198
Mega Guru

Hi all,

I have made custom Assign to me UI action that should also assign the assignment group and assigned to fields of the user, however it is not working and keep asking for Assignment group is mandatory, not sure what's wrong with the scritp, please take a look:

I have deactivated the OOTB Assign to me as it was on Task table and we do not want on all tables, just Incidents and Sctask. I have a custom field on the users record that has the primary assignment group of the user and should populate with this to the record.

Table: Incident

Condition: gs.hasRole('itil') && current.active !=false

var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
current.assigned_to = gs.getUserID();
current.assignment_group = gr.getValue('u_primary_group');
current.update();
action.setRedirectURL(current);

1 ACCEPTED SOLUTION

Hi Sam,

you would require first to make that field as non-mandatory since you are filling it with UI action script;

Also assignment_group you are setting with u_primary_group field from sys_user

Is that logged in user member of that primary group if yes then it is fine

have the ui action as both client and server side and use this script and test once

set the client checkbox true on UI action; in the onclick field of UI action mention the function name

runClientCode()

function runClientCode(){
   g_form.setMandatory('assignment_group',false);
   gsftSubmit(null, g_form.getFormElement(), '<button_action_name>'); 
}

if(typeof window == 'undefined')
   updateRecord();

function updateRecord(){

var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
current.assigned_to = gs.getUserID();
current.assignment_group = gr.getValue('u_primary_group');
current.update();
action.setRedirectURL(current);

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Hi Sam,

So the update is not working. Did you check any before update business rule which is restricting this?

you need to debug this

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Manage to work with your script.

Alikutty A
Tera Sage

Hi Sam,

Have you set the Assignment group as mandatory using a UI policy or client script? Can you make it not mandatory and see if this works?

Sajilal
Mega Sage

Hello,

Please check if you have any OnSubmit Client Script if the error is only coming when pressing the button. Also try changing your action name on the UI action if it resolves.

Please mark the answer as Correct and Helpful, if it works for you.

Regards,
Sajilal