We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Assigned To not auto-populating when Assignment Group is "Network" (Incident onChange Client Script)

DurgaPrasadCH
Mega Contributor

Hi Everyone,

I am working on an Incident onChange Client Script where I need to automatically set the Assigned To field when the Assignment Group is set to "Network".

However, the script is not working as expected, and I am not sure what I am missing.

Below is the code I have written:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

if (newValue === "Network") {
g_form.setValue("assigned_to", fred.luddy);
}
}

 

My requirement:
When Assignment Group = Network, Assigned To should automatically populate with a specific user.

 

Could anyone please help me understand what might be wrong here?

 

Thank you in advance for your support.

1 ACCEPTED SOLUTION

miftikhar20
Kilo Patron

Hi @DurgaPrasadCH,

The issue in your script is that you're trying to set the value using fred.luddy, which is not valid in a client script. The assigned_to field is a reference field and it expects a sys_id, not a display name or object reference.

 Also, your condition must match the sys_id of the Assignment Group .

You should update your script like this:

 
// sys_id of Network group 
if (newValue == 'NETWORK_GROUP_SYSID_HERE')
{ 
// sys_id of the user to assign 
g_form.setValue('assigned_to', 'USER_SYSID_HERE');
}

  

If my response helped, please mark it as the accepted solution so others can benefit as well.    

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

View solution in original post

2 REPLIES 2

miftikhar20
Kilo Patron

Hi @DurgaPrasadCH,

The issue in your script is that you're trying to set the value using fred.luddy, which is not valid in a client script. The assigned_to field is a reference field and it expects a sys_id, not a display name or object reference.

 Also, your condition must match the sys_id of the Assignment Group .

You should update your script like this:

 
// sys_id of Network group 
if (newValue == 'NETWORK_GROUP_SYSID_HERE')
{ 
// sys_id of the user to assign 
g_form.setValue('assigned_to', 'USER_SYSID_HERE');
}

  

If my response helped, please mark it as the accepted solution so others can benefit as well.    

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

Hello Miftikhar,

 

I have tried the suggested steps, but the issue still persists. Kindly check on your side and provide the exact solution at your convenience