Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

How to make Assigned To mandatory when clicking Resolve button on HR Case

GopiKrishna Sir
Tera Contributor

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:

 

function resolve() {
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_HR Comment Dialog');
        var msg = new GwtMessage().getMessage('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');
}

if(typeof window == 'undefined')
   resolveHRCase();
function resolveHRCase(){
if (current.skip_automatic_user_acceptance_state)
    current.state = 3;
else {
    current.sla_suspended = true;
    current.sla_suspended_on = new GlideDateTime().getDisplayValue();
    current.state = 20;
}
current.update();

action.setRedirect(current.getLink(true));
}  
 

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!

4 REPLIES 4

Abhishek Pal
Giga Guru

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

Its_Azar
Mega Sage

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. 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,
Azar
Serivenow Rising Star
Architect@ KPMG.

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.

Ankur Bawiskar
Tera Patron

@GopiKrishna Sir 

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! 🙏

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