Set Field Using Client Script

billv6
Kilo Expert

Hi Guys,

 

I'm having some issues to update a field when user select an specific option on other field.

 

I have the Status field and according to the option user selects on this field, the Assigned To field needs to be populated or updated using the following script:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
     
     var status = g_form.getValue('install_status');
     
     if (status == 7) {
           g_form.setValue('assigned_to', 'ASSET RETIRED Generic User');
     }
     
     else if (status == 9) {
           g_form.setValue('assigned_to', 'ASSET DISPOSED Generic User');
     }
     
     else if (status == 6) {
           g_form.setValue('assigned_to', 'ASSET STOCK Generic User');
     }
}

 

The problem is: The field is automatically populating every time I change the Status field, but when I try to save or update the record, I'm getting the following error: "Invalid Update, Match not found, reset to original" but those three users in the script exists. If I try to update them manually, it works!


Any ideas on how to solve this issue?


Thanks!

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,



You have to use the script as :


g_form.setValue('assigned_to', 'sys_id of the user'); //you have to set the sysid of the user




Let me know if you have any questions




Thanks,


Pradeep Sharma


View solution in original post

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,



You have to use the script as :


g_form.setValue('assigned_to', 'sys_id of the user'); //you have to set the sysid of the user




Let me know if you have any questions




Thanks,


Pradeep Sharma


billv6
Kilo Expert

It works! Thanks Pradeep!


Subhajit1
Giga Guru

Or you can use g_form.setDisplayValue(assigned_to', 'ASSET RETIRED Generic User').