Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to detect if the current user is system account. With SPServices i can find user login name:

var thisUserName = $().SPServices.SPGetCurrentUser({
                        fieldName: "Title",
                        debug: false

                        });

But with system account logged in, this JS function gives the login name of the real user so i cannot define that the user is system account.

share|improve this question
    
I'm not sure why this wouldn't work as well as any of the other posts below. Weren't you getting the system account name? –  Marc D Anderson Feb 7 '13 at 4:25
    
No the code block in my question post does not give system account, it only gives the login name of the real user. –  ozdogan Feb 7 '13 at 7:14
    
That's exactly what the get_currentUser() functions below will give, so I'm not sure what you mean. –  Marc D Anderson Feb 7 '13 at 12:17

3 Answers 3

up vote 1 down vote accepted

You can achieve required functionality using sharepoint javascript object model, try following code:

SP.SOD.executeOrDelayUntilScriptLoaded(runMyCode, "SP.js");
function runMyCode() {
    var ctx = new SP.ClientContext.get_current();
    var web = ctx.get_web();
    ctx.load(web);
    var user = web.get_currentUser();
    user.retrieve();
    ctx.executeQueryAsync(
        function () {
                    //success function
            if(user.get_loginName() == "SHAREPOINT\\system"){
                alert(String.format("This is system account - {0}", user.get_loginName()));
            } else {
                alert(String.format("This is normal user - {0}", user.get_loginName()));
            }
        }, 
        function (data) {
            //notify the failure
    });
}
share|improve this answer

By this code you should able to get the "system\account" user:

   context = new SP.ClientContext.get_current();
   web = context.get_web();
   var currentUser = web.get_currentUser();
   alert(currentUser);
share|improve this answer

I don't know how the SPServices library works, but if you need the user name/login to be displayed as "System Account" you can try this:

var context = new SP.ClientContext.get_current();
var web = context.get_web();
theUser = web.get_currentUser();
context.load(this.theUser);

context.executeQueryAsync(.........);

After that theUser.get_title() should report "System Account", while theUser.get_loginName() should display "SHAREPOINT\system" (Note: I have left out the call back code for executeQueryAsync)

Can this be enough for you?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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