Whats the total number of xs in:
Q: Sharepoint 2010 JSOM run script under impersonated user account or elivated privilages Secnario:I have a SharePoint list with two fields loginNme and message are stored. Based on logged in user I need to show different messages. This list has unique permissions i.e. only one particular group can only see the items in this list. SO I gave contribute access to one group. No other group or users can even see this list items.
Problem: The script to show unique messages based on logged in user works only for user who have contribute writes on the list. For other users who do not have any permissions on the list.The script doesnt work, it says list is not found. So how can I impersonate the JSOM code so that the script executes for users who do not have permissions?
Below is my script:-
function init() {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var currentUser = web.get_currentUser();
    var employerLoginList = web.get_lists().getByTitle(ListName);
    var query = new SP.CamlQuery;
    query.set_viewXml(<View><Query><OrderBy><FieldRef Name=ID/></OrderBy></Query></View>);
    var items = employerLoginList.getItems(query, Include(Id, LoginName, Message));
    context.load(currentUser);
    context.load(items);
    var sender = { currentUser: currentUser, items: items };
    context.executeQueryAsync(function () { succeed(sender); }, failed);
}

function succeed(sender, args) {
    var user = sender.currentUser.get_id();       
    var count = sender.items.get_count();
    var enumerator = sender.items.getEnumerator();
    if (count > 0) {
        while (enumerator.moveNext()) {
            var item = enumerator.get_current();
            var loginName = item.get_item(LoginName).get_lookupId();               
            var message = item.get_item(Message);
            if (user === loginName) {
                $(.divMessage).text(message);
                return;
            }
        }
    }
}

function failed(sender,args) {

}  


A: Impersonation is not possible from Client Side JavaScript.


*

*Create a Read Only Group and provide permissions to all users to read the list items


A: You cannot directly elevate privileges to run the client side code as that would be a violation of client side scripting. However you can impersonate using clientcontext as below
ClientContext context = new ClientContext(http://server/);
context.Credentials = new NetworkCredential(user, password, domain);


user
In that passage, there are sixteen occurrences of the letter "x."
assistant