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>' +
                        var camlQuery = new SP.CamlQuery();
                        this.productcollection<%=SerialNum%> = list.getItems(camlQuery);

                        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.

1 Answer 1


You need to generate SP.Context of the root web.

You can use syntax

clientContext = new SP.ClientContext(rootWebUrl);
  • After using the above syntax i get the following error: "Sys.InvalidOperationException: The object is used in the context different from the one associated with the object." Would you please advice.
    – WaleedMuh
    Mar 30, 2015 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.