How to make Assigned To mandatory when clicking Resolve button on HR Case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Community,
I have an existing Resolve UI Action on the HR Case (sn_hr_core_case) table.
Currently, when the user clicks Resolve, the system prompts the user to enter Work Notes and then resolves the case.
Below is the existing UI Action script:
I need to modify this existing functionality so that Assigned To is required when the Resolve button is clicked.
Expected behavior:
- If Assigned To is blank, do not allow the case to be resolved and make/display Assigned To as mandatory.
- If Assigned To is populated, continue with the existing Work Notes popup and Resolve functionality.
- The existing Work Notes popup behavior should not be affected.
- Other actions such as Spam/Duplicate should continue to allow Assigned To to be blank.
What would be the best way to add the Assigned To validation specifically to the Resolve UI Action without affecting the existing functionality?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @GopiKrishna Sir ,
Since you want Assigned To to be mandatory only when the user clicks the Resolve UI Action, I would not create a global UI Policy or Data Policy.
The cleanest solution is to add the validation directly at the beginning of the existing Resolve client function, while leaving the Work Notes popup logic unchanged.
Add this at the TOP of your existing resolve() function:
function resolve() {
// Validate Assigned To before continuing with Resolve
if (!g_form.getValue('assigned_to')) {
g_form.setMandatory('assigned_to', true);
g_form.showFieldMsg(
'assigned_to',
'Assigned To is required before resolving the HR Case.',
'error'
);
return false;
}
// Keep your existing Work Notes logic below
if (g_form.getValue('work_notes') == '') {
var sysId =
typeof rowSysId == 'undefined' ||
rowSysId == null
? g_form.getUniqueValue()
: rowSysId;
var dialogClass =
GlideModal
? GlideModal
: GlideDialogWindow;
var dialog =
new dialogClass(
'sn_hr_core_HRCommentDialog'
);
var msg =
'Please provide a summary of the work performed';
dialog.setTitle(msg);
dialog.setPreference(
'sysparm_task_sys_id',
sysId
);
dialog.setPreference(
'sysparm_ok_method_name',
'resolveCase'
);
dialog.setPreference(
'sysparm_task_table',
'sn_hr_core_case'
);
dialog.setPreference(
'sysparm_is_required',
true
);
dialog.setPreference(
'sysparm_is_comment',
false
);
dialog.render();
return false;
}
gsftSubmit(
null,
g_form.getFormElement(),
'resolveCase'
);
}
I would also add a server-side validation at the beginning of your existing resolveHRCase() function.
This protects the action if the client-side validation is bypassed.
Add:
function resolveHRCase() {
if (current.getValue('assigned_to') == '') {
gs.addErrorMessage(
'Assigned To is required before resolving the HR Case.'
);
action.setRedirectURL(current);
return;
}
// Keep ALL your existing resolveHRCase()
// logic below this point.
// existing code...
}
So the execution becomes:
User clicks Resolve
-> Assigned To empty
-> Assigned To becomes mandatory
-> Error shown
-> Resolve stops
User populates Assigned To
-> Clicks Resolve again
-> Existing Work Notes popup continues normally
-> Existing HR Case resolve logic executes
This meets your requirement without changing the normal behavior of the form.
I would specifically avoid:
- Making Assigned To mandatory at Dictionary level
- Creating a Data Policy
- Creating a Business Rule only to make the field mandatory
- Changing the existing Work Notes modal
- Creating another Resolve UI Action
- Using DOM manipulation
A UI Policy with:
State = Resolved
could also make Assigned To mandatory, but it would apply whenever the case enters Resolved state, not specifically when this Resolve button is clicked.
Since your requirement is specifically tied to this UI Action, validation inside the UI Action is more precise.
ServiceNow's GlideForm setMandatory() method makes the field visually mandatory and prevents normal form submission while it remains empty.
Related Community example for the same pattern:
A Resolve UI Action can validate the required field on the client, call:
g_form.setMandatory('field_name', true);
and only execute gsftSubmit() after the required value exists.
Hope this helps!
If this response helped, please mark it as Helpful.
If it resolves your issue, please Accept it as Solution.
Kind Regards,
Abhishek Pal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi there @GopiKrishna Sir
The easiest way is to validate assigned_to at the start of the existing resolve() function, before the Work Notes popup. If it’s blank, use g_form.setMandatory('assigned_to', true) and return false; if it’s populated, let the existing Work Notes logic continue as-is. This keeps Assigned To mandatory only for Resolve and won’t affect actions like Spam/Duplicate.
Kind Regards,
Azar
Serivenow Rising Star ⭐
Architect@ KPMG.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have already tried this but system is asking to leave that page if changes are not saved manually after entering the assigned to value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
If that's OOTB UI action or custom UI action then simple solution is
-> show this button only when Assigned to is not empty
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader