OOB "Auto fill Assigned to field" Client Script

jalipatisir
Tera Contributor

The below onChange client script on "Assignment group" field will set the "Assigned to" field to the "Assignment group manager" and this is happening on only in native view, not in HR agent workspace.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
ScriptLoader.getScripts('sn_hr_core.utils_ui.jsdbx', function(){
getGlideRecord('sys_user_group',newValue , setAssignTo);
});
function setAssignTo(group){
if (group)
g_form.setValue('assigned_to', group.manager);
}

Why this behaviour required to assign to group manager instead of group members?

Thanks,
Sireesha.

2 ACCEPTED SOLUTIONS

Chaitanya ILCR
Kilo Patron

Hi @jalipatisir ,

 

that should be because of the ScriptLoader 

if you want this to work recreate the logic using GlideAjax and client callable script include

 

if your organization don't need it you can disable it.

 

Why this behaviour required to assign to group manager instead of group members?

  1. Accountability and Ownership

    • The group manager is typically responsible for overseeing the work of the group.
    • Assigning the task to the manager ensures someone is accountable for triaging or reassigning the task appropriately.
  2. Triage and Delegation

    • Managers often act as triage points. They receive the task and then delegate it to the most appropriate team member.
    • This is especially useful when the system cannot determine the best-suited member automatically.
  3. Consistency Across Processes

    • In many workflows, especially in HR or IT, assigning to the manager ensures a consistent entry point for handling requests.
  4. Avoiding Random Assignment

    • Without a clear rule, assigning to a random group member could lead to confusion or delays if the person is unavailable or not the right fit.

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@jalipatisir 

script loader is not supported in workspace.

Since you mentioned it's an OOTB script then it means ServiceNow intended not to run this on workspace.

For making it work on the workspace you can create another onChange and use getReference with callback and ensure it runs only on workspace view

Uncheck Global checkbox and mention the workspace view name

AnkurBawiskar_0-1750828589792.png

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    if (newValue == '') {
        g_form.clearValue('assigned_to');
    }

    var ref = g_form.getReference('assignment_group', callBackMethod);
}

function callBackMethod(ref) {
    if (ref.manager)
        g_form.setValue('assigned_to', ref.manager);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

3 REPLIES 3

Chaitanya ILCR
Kilo Patron

Hi @jalipatisir ,

 

that should be because of the ScriptLoader 

if you want this to work recreate the logic using GlideAjax and client callable script include

 

if your organization don't need it you can disable it.

 

Why this behaviour required to assign to group manager instead of group members?

  1. Accountability and Ownership

    • The group manager is typically responsible for overseeing the work of the group.
    • Assigning the task to the manager ensures someone is accountable for triaging or reassigning the task appropriately.
  2. Triage and Delegation

    • Managers often act as triage points. They receive the task and then delegate it to the most appropriate team member.
    • This is especially useful when the system cannot determine the best-suited member automatically.
  3. Consistency Across Processes

    • In many workflows, especially in HR or IT, assigning to the manager ensures a consistent entry point for handling requests.
  4. Avoiding Random Assignment

    • Without a clear rule, assigning to a random group member could lead to confusion or delays if the person is unavailable or not the right fit.

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Ankur Bawiskar
Tera Patron
Tera Patron

@jalipatisir 

script loader is not supported in workspace.

Since you mentioned it's an OOTB script then it means ServiceNow intended not to run this on workspace.

For making it work on the workspace you can create another onChange and use getReference with callback and ensure it runs only on workspace view

Uncheck Global checkbox and mention the workspace view name

AnkurBawiskar_0-1750828589792.png

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    if (newValue == '') {
        g_form.clearValue('assigned_to');
    }

    var ref = g_form.getReference('assignment_group', callBackMethod);
}

function callBackMethod(ref) {
    if (ref.manager)
        g_form.setValue('assigned_to', ref.manager);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

jalipatisir
Tera Contributor

Thanks for your suggestions!