- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 10:34 AM
I have a field on a form that the business would like to be required if another field is set to "Deploy".
I think a client script is probably the correct route to go but would like to ask the question,
Which is the best way to make the field required if the status field changes to "deploy" and not required if it's not "deploy"?
Business rule?
UI Policy?
Client Script?
Again I'm leaning toward client script with an OnChange and I'll probably have to use an IF statement in there but could use some help with that if someone could offer some sample code.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 10:56 PM
Hello ,
You can use below script in onChange client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue == 2){ // instead of "2" give background value of your field
g_form.setMandatory('assignment_group', true); // your field name to make it mandatory
}else{
g_form.setMandatory('assignment_group', false); // your field name to make it non mandatory
}
}
Also easy way to do it using UI policy with no code.
Thanks ,
Valmik Patil

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 10:57 PM
Hi @Community Alums ,
We always prefer OOB Configuration in ServiceNow. If its not possible with configuration then we can opt customization. So here in your case UI Policy is best practice to set field mandatory.
Kindly mark correct and helpful if applicable.