Why I am getting "GlideGuid is not allowed in scoped applications" error while executing the Scripted REST API?

Phalguna
Mega Contributor

Hi 

I am getting following error error while calling the Scripted REST API from REST API Explorer,

GlideGuid is not allowed in scoped applications

please find the code snippet below which is used inside scripted REST API.

var data = request.body.data;
var user_name = data.user_name;
var action_type = data.action_type;
var location = data.location;
// finding sys id of given user
var grUser = new GlideRecord('sys_user');
grUser.addQuery('name',user_name);
grUser.query();
if(grUser.next()){
user_id = grUser.getValue('sys_id');
}
// finding sys id of provided location
var grloc = new GlideRecord('cmn_location');
grloc.addQuery('name',location);
grloc.query();
if(grloc.next()){
location_id = grloc.getValue('sys_id');
}
// Creating Request, Requested Item and setting variables
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId); //calling the cart API
var item = cart.addItem('b344************9b68a'); //Used proper sys_id 
cart.setVariable(item, 'select_action', action_type);
cart.setVariable(item, 'location', location_id);
cart.setVariable(item, 'select_the_user_to_add_or_remove_vip_access', user_id);
var req = cart.placeOrder();

 

Regards,

Phalguna

5 REPLIES 5

Mike Patel
Tera Sage

try using gs.generateGUID() instead of GlideGuid.generate(null);

or try

var cart = new sn_sc.CartJS();

gs.generateGUID() is working ,Thank you Mike

Please mark answer correct to close out the thread.

Hi,

you can use below code

it would work for both global and custom scope

var cart = new sn_sc.CartJS();
		var item =
		{
		'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
		'sysparm_quantity': '1',
		'variables':{
		'user': 'Abel Tuter',
		'location': 'Texas',
		'created_by': 'abel.tuter',
		'action_type': 'hello'
		}};
		var cartDetails = cart.addToCart(item);
		gs.info(cartDetails);
		var checkoutInfo = cart.checkoutCart();
		gs.info(checkoutInfo);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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