Using "gr" in Scripts can result in variables getting clobbered by other scopesIssue When writing server-side scripts (Script Includes, Business Rules, etc.) the use of "gr" when not included in a function or other limited scope construct, it can get 'corrupted' during script execution. This same concept is also discussed in more depth in Best Practice: Why using 'gr' as a GlideRecord variable name in custom scripts is always a bad idea.ReleaseAllCauseThe following example demonstrates the behavior, when run in Scripts Background var gr = new GlideRecord("sys_user_grmember");gr.addQuery("user=02c1f2c71b774450371adb9edc4bcb33");gr.query();gs.print("There are " + gr.getRowCount() + " records for user=02c1f2c71b774450371adb9edc4bcb33");while(gr.next()){ gs.print("Found record for " + gr.user.getDisplayValue() + " and group: " + gr.group.getDisplayValue() + "."); gr.deleteRecord();} In the above example the user value is the sys_id of a user with three records in the sys_usr_grmember table. The output shows 3 records were found, but execution stop after deleting one record. and this example deal with the Contextual Security: Role Management plugin being active, and that contains platform logic to re-allocate roles.ResolutionThe use of "gr" as the variable name of a JavaScript object is subject to scope bleed as OOB or other scripts can overwrite that object. Wrap script logic in a function and call the function to prevent scope bleed. The following example will result in the deletion of each record meeting the query condition. However, this doesn't solve every permutation of the problem. To really be on the safe side use unique and descriptive variable names like "roleMemberToDelete". deleteGroups();function deleteGroups() { var gr = new GlideRecord("sys_user_grmember"); gr.addQuery("user=02c1f2c71b774450371adb9edc4bcb33"); gr.query(); gs.print("There are " + gr.getRowCount() + " records for user=02c1f2c71b774450371adb9edc4bcb33"); while(gr.next()){ gs.print("Found record for " + gr.user.getDisplayValue() + " and group: " + gr.group.getDisplayValue() + "."); gr.deleteRecord(); }}