Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Access to api 'put(sys_user_preference.value)' from scope 'sn_hr_sp' has been refused due to the api's cross-scope access policy - How to fix this erroe

Priyanga7
Kilo Guru

Access to api 'put(sys_user_preference.value)' from scope 'sn_hr_sp' has been refused due to the api's cross-scope access policy

 

How to fix this error.

 

In Header widget I used the below lines

 

Server Side - 

var myreturn = false;
var prefVal = gs.getUser().getPreference("portal.first.login");
if (prefVal === null) {
// var currentTime = new GlideDateTime();
// gs.getUser().setPreference("portal.first.login", currentTime);
var grPref = new GlideRecord("sys_user_preference");
grPref.initialize();
grPref.name = "portal.first.login";
grPref.value = new GlideDateTime();
grPref.insert();
myreturn = true;
}
gs.info("Value in myreturn"+myreturn);

data.myval=myreturn;

 

Client Controller - 

 



if(c.data.myval)
{

$location.url("/esc?id=hri_user_profile&sys_id="+$scope.userID);

}

Any idea to prevent this error.

1 ACCEPTED SOLUTION

Priyanga7
Kilo Guru

Got cross scope errors while using the Gliderecord for sys_user_preference in ESC Header widget. So I used Script Include and got value in service script of widget and redirected it further based on condition.

Client Callable Script Include

var spPortalCall = Class.create();
spPortalCall.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: 'spPortalCall',

isFirstTime:function(){
var isNew = false;
var prefVal = gs.getUser().getPreference("portal.new.login");
if (prefVal === null) {
isNew = true;
gs.getUser().setPreference("portal.new.login", new GlideDateTime());

return isNew;

}

});

 

In Header Widget - Client script added the below lines

 

if (c.data.value) {
location.href= "/esc?id=hri_user_profile&sys_id=" + $scope.userID;
//alert("Location is "+ location.href);
// $location.url("/esc?id=hri_user_profile&sys_id=" + $scope.userID);

}

 

In Header Widget - Server script added the below lines

 

data.value = new global.spPortalCall().isFirstTime();
gs.info("my data value --------" + data.value);

 

 

Thanks!!

View solution in original post

10 REPLIES 10

Hi - looking at your post here - we have a similar issue and cannot access the referenced article - is there any summary or content available elsewhere that you know of? Thanks