Create global records from scoped application script

bwhiton
Tera Contributor

I am creating a scoped application.   Within the application, I'm creating a workflow to sync products from an external source.   This sync process will create sc_cat_items in ServiceNow.   However, when executing the following code:

var catItems = new GlideRecord('sc_cat_item');

catItems.initialize();

catItems.name = 'bogus';

catItems.active = 'true';

catItems.insert();

I get the following error:

"Create operation against 'sc_cat_item' from scope 'x_moda_myapplication_ca' has been refused due to the table's cross-scope access policy"

The only way to successfully create the record is to go to the sc_cat_item table and edit the Application Access so ALL applications 'Can Create'.  

However, this seems like a bad practice.   Is there a way to create a record (like sc_cat_item) from within a script running in a custom application?   Or, should I be executing this script in the global space.. somehow?   Also.. I tried to modify the 'Cross Scope Privelage' within my application, as shown below, but it did not seem to help.   Screen Shot 2017-03-28 at 8.27.38 AM.png

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Bob,



With the latest release(Geneva onwards) we have OOTB API's for service catalog which would fulfill the above task with out any modification of application access settings. Please refer below link for more info.


Reference: https://developer.servicenow.com/app.do#!/api_doc?v=geneva


Thank you for the information.   It appears that CatItem would meet my needs.   However, I can not seem to get it to work.   For example, if I attempt to do the following (through 'Scripts - Background'):



var newsysid = CatItem.create(false);   // or var newsysid = new CatItem();


gs.info('newsysid'+newsysid);



I get the following error:



Evaluator: org.mozilla.javascript.EcmaError: "CatItem" is not defined.



Can you provide a quick example?   Thanks!


manikorada
ServiceNow Employee
ServiceNow Employee

Bob,



The syntax for this is :



var catItem = new sn_sc.CatItem();


catItem.setAttributes({"name": "My Catalog Item"});


var catItemSysId = catItem.create();