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

Using the below SPServices call, I can get the display name of the author of a list item:

$().SPServices({
                operation: "GetListItems",
                async: false,
                listName: "MyList",
                CAMLViewFields: "<ViewFields Properties='True' />",
                CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Integer'>" + id + "</Value></Eq></Where></Query>", 
                completefunc: function (xData, Status) {
                    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
                        author = $(this).attr("ows_Author");
                    });
                }
            });

This gets me a name like "43#;John Doe". How can I get the account name instead? Like "john.doe". So I can use it to get the user's manager's account name.

Thanks.

share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

You need to use the Users and Groups web service. If you call the GetUserCollectionFromWeb() method, it will return an XML node containing all the users on the site. You can then look up your specific user using the ID returned in your User node - in the case of the example - 43.

The web service will return a collection of User nodes which have an ID attribute one of which will match your ID, and a LoginName attribute which will be the information you are after.

The SPService reference to the service is here

The MSDN reference to the service is here

share|improve this answer
add comment

I've read that if you include:

<QueryOptions><ExpandUserField>TRUE</ExpandUserField></QueryOptions>

in your CAMLQuery, it will bring back the account name in addition to the display name.

However, it is not working in WSS for me, and I vaguely recall it might only work in MOSS.

share|improve this answer
add comment

I've done this same thing in C#, using the format style of the username you provided, and used the class SPFieldUserValue to get the actual user object, seen below:

string user = new SPFieldUserValue(web, "43#;John Doe").User.Name;

I'm not familiar enough with the client object model to provide an example for you, but take a look here. See if either of the two solutions provided help you. They are using the FieldUserValue class, the client object model implementation of the SPFieldUserClass.

share|improve this answer
    
+1. Thanks a lot Tim, spot on. –  DeeMac Sep 26 '12 at 14:21
add comment

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.