How to solve the "Match not found, reset to original" error?

Claudio2
Kilo Contributor

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.

find_real_file.png

The following image shows the error.

find_real_file.png

 

Thanks in advance

Claudio M.

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

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.

View solution in original post

6 REPLIES 6

Onkar Pandav
Tera Guru

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.

https://community.servicenow.com/community?id=community_question&sys_id=860384fcdb259b802b6dfb651f96...

https://community.servicenow.com/community?id=community_question&sys_id=7edee4e8db863b40d58ea345ca96...

 

Mark helpful and correct based on impact.

Mwatkins
ServiceNow Employee
ServiceNow Employee

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.

Mwatkins
ServiceNow Employee
ServiceNow Employee

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.

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

find_real_file.png