I have 2 sites for 2 different groups. One group has access to site1 and one group has site2. Each group does not have access to the others site.

I have a query however that needs to access each site upon entry of a field to see if it exists. Unfortunately the query will fail due to the user not having access to one of the sites.

Is there a way that I can pass credentials that have access to query?

This is my code:

var clientContext = new SP.ClientContext('https://mysite.sharepoint.com/site/site1/');
var oList = clientContext.get_web().get_lists().getByTitle('list');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'Title\'/>' +
    '<Value Type=\'Text\'>'+check+'</Value></Eq></Where></Query></View>');
this.collListItem = oList.getItems(camlQuery); 
clientContext.load(collListItem, 'Include(Id, DisplayName)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

You can impersonate only using server side code.

So either provide read access or create a custom web part for displaying data.

  • Can't give these users read access, how would I go about creating a web part to do that? – Tom May 5 '15 at 20:22
  • You need to use Visual Studio. And create a SharePoint project. Then use a visual web part. Drop a GridView control. And use elevated to query data. – Amal Hashim May 5 '15 at 20:24
  • Can I use my script to call a C# code to impersonate a user that would have access to both sites? – Tom May 6 '15 at 15:02
  • In that case you should deploy that c# code as a web service – Amal Hashim May 6 '15 at 15:07
  • How would I call that functionality in the javascript before I run my query? – Tom May 6 '15 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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