Anish Reghu
Kilo Sage
Kilo Sage

Dear fellow developers or concerned ServiceNow team addressing it,

 

I am reporting a bug here.

 

The documented .find() method on ServiceNow GlideRecord API does not work.

It is intended to return a true/false, but the key part is it moves to the first record that matches the find 'value' parameter. BUT, instead....

It creates a duplicate incident with the same Incident number.

 

var GR = new GlideRecord("incident");
GR.query();
if (GR.find("number", 'INC0009003')) //KEY PART - YOU FETCH THE GlideRecord object on the queried record.
{       
	gs.print("Short description: " + GR.short_description);
    GR.short_description = "UPDATED" + GR.short_description; GR.update();
	gs.print("Updated Short Description: "+ GR.short_description);
} else {
    gs.print("Incident not found!");

 

OUTPUT:

 

AnishReghu_0-1751508889864.png

Fig: A new duplicate record every time, the script is run, the reason .find() method.

 

When the above code is executed, as per the API documentation, it is expected that the relevant record is fetched and is updated via the GlideRecord object. BUT.... this creates a record and that too a duplicate incident even with the same incident number.

 

Please fix it.

 

Regards,

Anish Reghu

19 Comments