UI action set Assign To field but prevented due to mandatory field

Jared Wason
Tera Guru

Hi,

On the incident form we have Assigned To as a mandatory field. I am trying to setup a UI action that automatically sets the logged in user to be assigned to the incident. However since the field is mandatory I am being prevented from continuing when clicking on the UI action. Is there some way for my UI action to ignore this requirement or a different route to get this solution? Below is my UI action and what is happening when user clicks the UI action.

 

JaredWason_0-1692114073793.png

 

 

 

JaredWason_3-1692114234250.png

 

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @Jared Wason ,

1. On UI action form we have Client check box select that and give function name n onClick field and use below code.

Refer below 

 

function setAssigneee(){
	g_form.setMandatory('assigned_to',false);
	g_form.setValue('assigned_to',g_user.userID);
	g_form.save();
}

 

Screenshot (42).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

2 REPLIES 2

Pavankumar_1
Mega Patron

Hi @Jared Wason ,

1. On UI action form we have Client check box select that and give function name n onClick field and use below code.

Refer below 

 

function setAssigneee(){
	g_form.setMandatory('assigned_to',false);
	g_form.setValue('assigned_to',g_user.userID);
	g_form.save();
}

 

Screenshot (42).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

SANDEEP28
Mega Sage

@Jared Wason You can create UI action as below. It will take care of all mandatory fields once you click on "Assign to Me" UI action.

 

Client checkbox should be checked and put "callClientScript();" in onClick field.

 

SANDEEP28_0-1692117432760.png

 

 

function callClientScript() {
    //Client Script
    var arr = g_form.getMissingFields();
    for (var x = 0; x < arr.length; x++) {
        g_form.setMandatory(arr[x], false);
        alert("Following fields are set Non Mandatory: " + arr[x]);
    }
    gsftSubmit(null, g_form.getFormElement(), "incident_assign_to_me");
}

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

function serverScript() {
	current.assigned_to = gs.getUserID();
    current.update();
    action.setRedirectURL(current);
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!