Cannot delete record(s) from background script

xiaix
Tera Guru

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:
find_real_file.png

I even go into the Workspace Location table (which is extended by most of the above listed tables) and set "Can delete" to true:
find_real_file.png

I try running the script... same result!

So then I do my least favorite thing of all in ServiceNow... open Studio (bleh)

find_real_file.png

Then try to go into settings:

find_real_file.png

But oh look, isn't this lovely:

find_real_file.png

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?

20 REPLIES 20

Okay, tried sn_wsd_core_workplace_profile and that didn't work either. 😞

Hi,

please raise HI ticket and let us know the update

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

Hmm...it should work. Please double-check your settings as appropriate.

If you've allowed "Can Delete" on the table settings, then the next step is cross scope privileges ...not restricted caller.

https://docs.servicenow.com/bundle/paris-application-development/page/build/applications/reference/c...

I've also assisted with suggesting to please try a scope other than global.

So 2 things have been adjusted here by me and they should work as I've tested them on my end.

Please double-check all settings.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

So I was able to get the Cross scope privilege records added:

find_real_file.png

 

By deactivating the Business Rule "Cross Scope Privilege Business Rule" which basically says that if the Source Scope is Global, don't create or update the record.

So even though I now have these 2 records, it still fails:

 

find_real_file.png

 

Hi,

So which table are you trying to delete from, both?

One of those has the target name in what appears to be the correct format (the table name - not table label) and the other doesn't.

And then your error message is talking about: sn_wsd_core_campus - which I'm not seeing a cross scope delete allowed for?

Please double-check your settings (I've mentioned this a few times, haha).

See if that helps?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!