Do not use “gr” as a variable name!
I’m not the first one telling you this, right?
I hope I’m the last one.
Why should you care?
I’m going to show you with the most basic example possible.
Not some edge case due to a complex workflow triggered by a MID server integration that nobody in your team even knows how it is supposed to work.
Let’s just update the names of some groups.
The groups that have “Database” as their parent.

Let’s prepend “[TEST]” to their name:
var gr = new GlideRecord('sys_user_group');
gr.addQuery('parent','287ee6fea9fe198100ada7950d0b1b73'); //Database
gr.query();
while(gr.next()){
gr.setValue('name', '[TEST] ' + gr.getValue('name'));
gr.update();
}
Code language: JavaScript (javascript)
Expected result

Actual result

Why did this happen?
Out of the box technical debt!
There are 52 business rules1 (as of Yokohama) that contain “var gr”, are active and don’t include the “function” keyword.
Among them is the “Auto business rule for Assessments”2, which overrides your variable.
What can you do about it?
- Do not use “gr” as a variable name!
- Read the following references about better naming conventions and encapsulating your code.
References
- KB0819895: Using “gr” in Scripts can result in variables getting clobbered by other scopes
- KB0713029: Best Practice: Why using ‘gr’ as a GlideRecord variable name in custom scripts is always a bad idea
- KB0858301: When running a script using the variable gr the result can be unexpected
- Better GlideRecord Variable Names (& why it Matters!)