Unable to insert record in table

mareks_p
Giga Contributor

I am trying to do this insert from Script - Background

// Add record
gs.log("Add warehouse item");
var gr1 = new GlideRecord('x_80267_inventory_warehouse');
gr1.initialize();
gr1.name = "building";
gr1.insert();
var ref = gr1.insert();
gs.log('Added item id: ' + ref);

and getting this error

[0:00:00.003] Script completed in scope global: script


*** Script: Add warehouse item
Security restricted: Create operation against 'x_80267_inventory_warehouse' from scope 'rhino.global' has been refused due to the table's cross-scope access policy
Security restricted: Create operation against 'x_80267_inventory_warehouse' from scope 'rhino.global' has been refused due to the table's cross-scope access policy
*** Script: Added item id: null

I have write permissions in attachment.

Any idea what is missing and not working for me?


1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

If you want to be able to create records in Global, you'll need to change the access levels on the table.



System Definition > Tables


Name = x_80267_inventory_warehouse


Open the Table record


Navigate to Application Access


Set 'Accessible from' to "All application scopes"


Set 'Can create' to TRUE


Save the record



table_access.PNG



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

5 REPLIES 5

srinivasthelu
Tera Guru

Hi Markeks,



Have you tried switching the scope at the bottom of the back ground scripte



4714232484724736.png?k=UtjaLEeo_08RtYMjCou9QYm8gTo


Yes, it works. But I am using code as a part of Unit test, and it is not working in that scope, that why I was thinking that I need permissions to make insert from any scope.


Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Im just guessing here, but it seems that when your'e using scripts - background your in the "global" scope, and then you try to insert records in your scoped application. Have you chosed the application in your application picker? So it doesn't say global there?



//Göran


The SN Nerd
Giga Sage
Giga Sage

If you want to be able to create records in Global, you'll need to change the access levels on the table.



System Definition > Tables


Name = x_80267_inventory_warehouse


Open the Table record


Navigate to Application Access


Set 'Accessible from' to "All application scopes"


Set 'Can create' to TRUE


Save the record



table_access.PNG



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022