I'm using JavaScript object model to retrieve data from a list located a root site.
My code is as below:
var clientContext;
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
clientContext = SP.ClientContext.get_current();
});
//var clientContext = SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var context = new SP.ClientContext.get_current();
this.web<%=SerialNum%> = clientContext.get_site().get_rootWeb();
var list = this.web<%=SerialNum%>.get_lists().getByTitle('<%=SubCategoryListName%>');
var query = '<View Scope=\'RecursiveAll\'>' +
'<Query>' +
'<Where>' +
'<Eq>' +
'<FieldRef Name=\'' + '<%=SubCategoryListParentCategoryColoumnName%>' + '\' LookupId=\'TRUE\'/>' +
'<Value Type=\'Lookup\'>' + chosenoption.value + '</Value>' +
'</Eq>' +
'</Where>' +
'</Query>' +
'</View>';
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
this.productcollection<%=SerialNum%> = list.getItems(camlQuery);
context.load(this.productcollection<%=SerialNum%>);
context.executeQueryAsync(Function.createDelegate(this, processProyects<%=SerialNum%>), Function.createDelegate(this, javascriptSPerror<%=SerialNum%>));
The problem is when I call this code from a page on the root site it works perfectly fine, but when I run it on a page located on a subsite I get the following error:
"Access denied, you don't have the permission to perform this action".
Any help is greatly appreciated.