Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

1) Go to cross scope application in left navigation

2) Add new entry there as below:

find_real_file.png

Thanks,
Ashutosh

I have already done this, still getting this error. Should I do for write operation as well?? 

I have created read, write and create record for the same. But still I get error. Though I get error I can able to create a record in sys_user_preference

Oh Yes. Its insert in your code. So Create should be selected.

Also on table you have to check

find_real_file.png


Thanks,
Ashutosh