How do you set the application scope in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 08:57 AM
There has to be a way to do this.
I need to delete about 28,000 records that were created by mistake during an import (I forgot to set the number field to coalesce=true!). Normally, I would just go to sys.scripts.do, do an encoded query on the table, and then run deleteMultiple. But it's a scoped application, and it's not letting me run deleteMultiple from the Global scope.
The little dropdown at the bottom that allows you to specify what scope you want to run it in only contains "global".
How do I run a script in a specific application scope?
This is the script I tried to run:
var hr=new GlideRecord('sn_hr_core_case');
hr.addEncodedQuery('sys_created_by=rick seiden');
hr.deleteMultiple();
But it said "Security restricted: Delete operation against 'sn_hr_core_case' from scope 'rhino.global' has been refused due to the table's cross-scope access policy"
I tried to add a sys_scope_privilege for GlideRecord.deleteMultiple, and got the same result.
Thanks for your help
Rick Seiden
PS: If this is a bad idea to try and allow deleteMultiple from the Global Scope, or run a script in a specific scope from sys.scripts.do, please tell me how to mass delete 28,000 records without deleting all records on the table (I want to keep some of them).
PPS: I tried writing a script include in the proper scope and calling that script include from the Global scope. That didn't work.
PPPS: I tried exporting the records I want to keep to an XML file and then using the Delete All Records feature of the Table module on the table. I got the same error as running it from sys.scripts.do
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2024 06:59 PM - edited 03-19-2024 06:59 PM
Yeah it may have changed along the way. I tried it before posting the comment above, and although at that time it was running in a different context I did get it to work then. But I too could not verify the functionality from a background script when I attempted to recently...
The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2024 07:05 PM
ok thanks...
i have just been suggested to have a global script which works on the return of a scoped script include to delete records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 03:09 AM - edited 03-20-2024 03:10 AM
Hello @rickseiden_info
its only possibility is to run the script in background script for the application created by the instance admin (starting with x_) for anything that is available with sn_ will not show up.
Only option being to create cross-scope or create fix script in required application scope & then use it.
Thanks,
Sanket Landge

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 05:11 AM - edited 03-20-2024 05:12 AM
As per my earlier post:
You can use DevTools' RunScriptInScope() function to execute code in different scopes.
Check this out:
https://www.wildgrube.com/servicenow-devtools
The RunScriptInScope() function uses the GlideScopedEvaluator class in a special way.
Please note that different topics have been discussed in this thread:
1. Running a script AS IF the script was contained in an application file in a different scope (this is where the GlideScopedEvaluator class as implemented in the DevTools can help).
2. Changing the scope of the current user session (this is what an admin can select on the top right of the navigation bar). The scope of the user session determines the scope in which changes are made and into which scope new Application File records are placed.
This is what you can set using this function:
PS: Fix scripts are evil! Do not use fix scripts! Never ever!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 05:25 AM
That explains the difference, thank you. When I posted above I was doing the same thing with GlideScopedEvaluator which seems to be what made the difference in my use case at the time.
The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.