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

9 REPLIES 9

Hi,

What is the type of Tracking on this application for HR Service Portal?


Thanks,
Ashutosh

Christian Prob2
Tera Guru

Hi Priyanga,

in case you log a case with ServiceNow to get the answer please share it here as well.

Thanks!

C.

Susan Britt
Mega Sage
Mega Sage

Check the Restricted Caller Access module also to see if there's a record there for the access request.

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!!

Annay Das
Tera Contributor