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

Prateek kumar
Mega Sage

Assignment group and Assigned to are related on incident table, meaning assigned to should be a member of assignment group then only it will accept the value.

and from your script, is u_primary_group a field on User record??

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

Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Hi Prateek,

yes u_primary_group is the field on the user records.

The above script still does not work - still asks me to add assignment group manually first.

 

find_real_file.png

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

Hi Ankur,

Tried that but it's not working. I can see the assignment group is going unmandatory, however, the page takes me back to the previous page, and when i go to check that incident it does not have the assignment group or assigned to populated.

Yes the logged in user (that is me) is the member of the primary group that's in the custom u_primary_group field.