1

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.

1 Answer 1

1

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

You can use syntax

clientContext = new SP.ClientContext(rootWebUrl);
1
  • 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. Commented 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.