- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2020 10:23 AM
Hello everone, I make a client script to automatize the fill of two fields of an Incident form. One of these is a reference field and the following is the script I wrote.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var tipo_agen = g_form.getValue('category');
if (tipo_agen === 'Agente Express') {
var ci_number = g_form.getDisplayBox('cmdb_ci').value;
var gr_atm_table = new GlideRecord('u_cmdb_ci_atm');
gr_atm_table.addQuery('u_numero_cajero', ci_number);
gr_atm_table.query();
while (gr_atm_table.next()) {
var tipo_atm = gr_atm_table.u_tipo_atm;
if (tipo_atm == 'AGENTE PROPIO') {
var mantenimiento = gr_atm_table.u_responsable_manto;
var sysid_responsable = g_form.getValue('assignment_group');
if (mantenimiento == 'DIEBOLD SAEX') {
g_form.setValue("assignment_group", sysid_responsable, 'DIEBOLD');
} else if (mantenimiento == 'TDP') {
g_form.setValue("assignment_group", sysid_responsable, mantenimiento);
}
var entidad = gr_atm_table.u_nombre_entidad;
g_form.setValue("short_description", entidad);
}
}
}
}
The reference field's name is 'assignment_group' and is filled in two cases with the 'u_responsable_manto' value. This belongs from the field Responsable Manto that belongs from the 'u_cmdb_ci_atm' table. To set the value of assignment_group reference field I use the setValue() function and pass the sys_id value. But I don't know if that value is the correct.
The following image shows the error.
Thanks in advance
Claudio M.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2020 12:58 PM
I think the issue is with this line
var sysid_responsable = g_form.getValue('assignment_group');
You should try with below script if assignment_group is a field in the cmdb atm table where you are trying to pull the values.
var sysid_responsable = gr_atm_table.getValue('assignment_group');
if (mantenimiento == 'DIEBOLD SAEX') {
g_form.setValue("assignment_group", sysid_responsable);
} else if (mantenimiento == 'TDP') {
g_form.setValue("assignment_group", sysid_responsable);
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2020 11:29 AM
Hi,
This happens when you update the reference field with a value rather than sys_id of the record.
You can search for error on community itself and may get resolution. Refer some links given below.
Mark helpful and correct based on impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2020 12:10 PM
The problem is you are trying to set the new value of the field to its current existing value with a different display value.
sysid_responsable will be populated with the current sys_id of the referenced value in the 'assignment_group' field. Then you are trying to setValue(field,value,display) with the current value but a new display.
var sysid_responsable = g_form.getValue('assignment_group');
if (mantenimiento == 'DIEBOLD SAEX') {
g_form.setValue("assignment_group", sysid_responsable, 'DIEBOLD');
} else if (mantenimiento == 'TDP') {
g_form.setValue("assignment_group", sysid_responsable, mantenimiento);
}
You need sysid_responsable to be populated with with new desired group sys_id; which I believe in this case would be the sys_id value of the gr_atm_table.u_responsable_manto field - I'm trying to read between the lines of your question, but it sounds like gr_atm_table.u_responsable_manto is a reference field that points to the sys_user_group table, just like assignment_group does.
To do really quick client-side debug I use "Javascript Executor". I don't even know if it is documented any more but you can access it from any standard ServiceNow form by pressing SHFT+CTRL+j.
From there you can access the g_form object; which I don't believe you can access directly from the normal Browser Debugger Console.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2020 12:21 PM
Actually, what are the field types of u_cmdb_ci_atm.u_tipo_atm and gr_atm_table.u_responsable_manto? If they are reference fields then you probably wouldn't be getting back values like 'AGENTE PROPIO' or 'DIEBOLD SAEX' when you dot-walk to them... you would be getting back sys_id's.
Are they choice list fields or string fields or something?
In that case you are going to need a 3rd query to match against the right assignment group by name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2020 12:41 PM
Hi Matthew,
Yes they are not reference fields. Both are Strings and for this particular use caso, gr_atm_table.u_responsable_manto can take two values: DIEBOLD SAEX and TDP. Then if it is DIEBOLD SAEX, the assignment_group field fills with DIEBOLD or on the other hand with TDP.
So, I need to get the sys_id from gr_atm_table.u_responsable_manto field and use it on the the setValue() function