Cannot delete record(s) from background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2020 08:12 AM
This is the script I'm trying to run (in Global scope):
(function () {
gs.print("First, deleting any old records.");
var record = false;
record = new GlideRecord('sn_wsd_core_workplace_profile');
record.query();
if (record.next()) {
gs.print("Deleting "+record.getRowCount()+' sn_wsd_core_workplace_profile records.');
record.deleteMultiple();
}
record = new GlideRecord('sn_wsd_core_space');
record.query();
if (record.next()) {
gs.print("Deleting "+record.getRowCount()+' sn_wsd_core_space records.');
record.deleteMultiple();
}
record = new GlideRecord('sn_wsd_core_floor');
record.query();
if (record.next()) {
gs.print("Deleting "+record.getRowCount()+' sn_wsd_core_floor records.');
record.deleteMultiple();
}
record = new GlideRecord('sn_wsd_core_building');
record.query();
if (record.next()) {
gs.print("Deleting "+record.getRowCount()+' sn_wsd_core_building records.');
record.deleteMultiple();
}
record = new GlideRecord('sn_wsd_core_campus');
record.query();
if (record.next()) {
gs.print("Deleting "+record.getRowCount()+' sn_wsd_core_campus records.');
record.deleteMultiple();
}
record = new GlideRecord('sn_wsd_core_site');
record.query();
if (record.next()) {
gs.print("Deleting "+record.getRowCount()+' sn_wsd_core_site records.');
record.deleteMultiple();
}
record = new GlideRecord('sn_wsd_core_region');
record.query();
if (record.next()) {
gs.print("Deleting "+record.getRowCount()+' sn_wsd_core_region records.');
record.deleteMultiple();
}
}();
This is the result I get:
*** Script: First, deleting any old records.
*** Script: Deleting 41 sn_wsd_core_workplace_profile records.
Security restricted: Delete operation against 'sn_wsd_core_workplace_profile' from scope 'rhino.global' has been refused due to the table's cross-scope access policy
*** Script: Deleting 41 sn_wsd_core_space records.
Security restricted: Delete operation against 'sn_wsd_core_space' from scope 'rhino.global' has been refused due to the table's cross-scope access policy
*** Script: Deleting 1 sn_wsd_core_floor records.
Security restricted: Delete operation against 'sn_wsd_core_floor' from scope 'rhino.global' has been refused due to the table's cross-scope access policy
*** Script: Deleting 1 sn_wsd_core_building records.
Security restricted: Delete operation against 'sn_wsd_core_building' from scope 'rhino.global' has been refused due to the table's cross-scope access policy
*** Script: Deleting 1 sn_wsd_core_campus records.
Security restricted: Delete operation against 'sn_wsd_core_campus' from scope 'rhino.global' has been refused due to the table's cross-scope access policy
*** Script: Deleting 1 sn_wsd_core_site records.
Security restricted: Delete operation against 'sn_wsd_core_site' from scope 'rhino.global' has been refused due to the table's cross-scope access policy
*** Script: Deleting 1 sn_wsd_core_region records.
Security restricted: Delete operation against 'sn_wsd_core_region' from scope 'rhino.global' has been refused due to the table's cross-scope access policy
Well, this sucks. So I change my application scope to "Workplace Safety Management", run the script, same issue.
So then, while I'm still in Workplace Safety Management scope, I go to each of those tables and click the "Delete" checkbox:
I even go into the Workspace Location table (which is extended by most of the above listed tables) and set "Can delete" to true:
I try running the script... same result!
So then I do my least favorite thing of all in ServiceNow... open Studio (bleh)
Then try to go into settings:
But oh look, isn't this lovely:
I mean c'mon.
Anyone know what magic mantra's I need to chant to allow me to run some scripts to clean out old records?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2021 06:43 AM
Hi
Having had the same trouble (and frustrations), I would point to Allen A's comment, where he says:
"If you've allowed "Can Delete" on the table settings, then the next step is cross scope privileges [..]"
If that helps please mark Allen's answer as correct - not mine 🙂
Anders
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2021 06:47 AM
Thanks 😉
Please mark it as Helpful, if so.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2021 07:05 PM
You should use OOB table cleaner OOB functionality to delete records and let platform do the cleanup of old records.
You don't' need to write any script.
Take a look into below
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2022 10:52 AM
Hi - I'm also facing the same issue. Trying to delete the record in one scoped application from another, but still getting the cross scope error.
Tried both approach -
- Allow can delete and allow configuration from the target table record
- Created a cross-scope privilege for deletion.
but still, the issue persists. Did you find any solution for the same?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 01:53 AM
So - I raised HI case for the same and the Engineer advised me to clear the cache by running the below code in the background script in global scope -
gs.invalidateCache();
Note: gs.invalidateCache() should be used as a last resort as this will degrade performance on the instance temporarily.
Also, this should not be used on production instances during business hours.
And after that the issue is resolved for me.
