GetUserProfileByName

Mar 21, 2013 at 3:48 PM
In my list, I have a people field that, when queried returns the user in this format:
1647;#LastName, FirstName Office etc

I need to use that format to query the user profile service to get his WorkPhone.

I have a function that pulls the WorkPhone when I provide the AccountName, which is the format used in our AD, formatted like: "domain/SmartCardID".
The function doesn't work when I supply the account as formatted in the people field (1647;#LastName, FirstName Office etc).
function getTheUserInfo(acct) { 
var ph;
$().SPServices({ 
      operation: "GetUserProfileByName", 
      async: false, 
      AccountName: acct, 
      completefunc: function(xData, Status) { 
           $(xData.responseXML).find("PropertyData").find("Name[text=WorkPhone]").each(function(){
                ph = ($(this).parent().find("Values").text());
                });   
      } 
    }); 
    return ph; 
    }
Coordinator
Mar 21, 2013 at 4:00 PM
Right, Don. You'll have to pass the user's account to that operation to get a successful response.

M.
Mar 21, 2013 at 4:10 PM
Is there a way to get profile info using the ID# from the UserInformationList?
i.e., extract the '1647' from the stored value in the people field: 1647;#LastName, FirstName Office etc
Coordinator
Mar 21, 2013 at 4:28 PM
You should be able to call GetUserCollectionFromSite to get all of the users in the current Site Collection (thus the User Information List, I believe). The ID is an attribute in the returned results http://msdn.microsoft.com/en-us/library/ms772702.aspx

M.
Mar 21, 2013 at 8:04 PM
There are a LOT of users in our UIL. I am trying to query the UIL with the ID criteria of the person, instead of pulling all users ala GetUserCollectionFromSite.
I even tried hard-coding the ID value of a known person.
It is still returning undefined.

Any thoughts????
Thanks again,
Don
function getAccountNameFromID()
    {
    //var thetdid = theTD.substring(0, theTD.indexOf("#") - 1);
    thetdid = 3; 
    //alert(thetdid); 
    $().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "User Information List",
            CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + thetdid + "</Value></Eq></Where></Query>",
            CAMLViewFields: "<ViewFields><FieldRef Name='LoginName' /></ViewFields>",
            completefunc: function (xData, Status) 
                {
                $(xData.responseXML).find("[nodeName='z:row']").each(function() 
                    {
                    theTDaccount += $(this).attr('ows_LoginName');
                    });
                
                }
            }); 
    alert(theTDaccount); 
    }
Coordinator
Mar 21, 2013 at 8:25 PM
.find("[nodeName='z:row']") won't work if you are using a version of jQuery > 1.7. Use the SPFilterNode function instead.

Are you getting valid results from the call?

M.
Mar 21, 2013 at 8:43 PM
I have jQuery 1.6.4 loaded on the site.
I use this syntax in all my queries:
$(xData.responseXML).find("[nodeName='z:row']").each(function()

...and they work fine.

The function above is returning 'undefined'.

If the answer is to upgrade JQ, I can just drop this little project and get to work fixing all the queries. That would probably be less frustrating anyway.

Don
Coordinator
Mar 21, 2013 at 8:51 PM
No, you don't have to upgrade jQuery, but they do make significant improvements. I'd suggest 1.8.3. The 1.9.x versions so far don't work with SPServices (their blunders not mine).

Add an alert in the completefunc to see what you are getting back, or look at things in the Net tab of Firebug.

alert(xData.responseText);

M.
Coordinator
Mar 21, 2013 at 8:54 PM
Edited Mar 21, 2013 at 8:54 PM
p.s. I just ran this in a test environment and it worked fine:
 $().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "User Information List",
            CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>1</Value></Eq></Where></Query>",
            CAMLViewFields: "<ViewFields><FieldRef Name='LoginName' /></ViewFields>",
            completefunc: function (xData, Status)  {
                alert(xData.responseText);
            }
 }); 
Coordinator
Mar 21, 2013 at 8:55 PM
And the column you want is ows_Name.

M.
Mar 21, 2013 at 9:02 PM
I put the responseText in a DIV...
"soap:ServerException of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."
$().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "User Information List",
            CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>13</Value></Eq></Where></Query>",
            CAMLViewFields: "<ViewFields><FieldRef Name='LoginName' /></ViewFields>",
            completefunc: function (xData, Status) 
                {
                $("#thisId").html("").append(xData.responseText);
                
                }
            });
Coordinator
Mar 21, 2013 at 9:08 PM
Ok, you're probably in a subsite, and the UIL is in the root of the Site Collection. Add the webURL option pointing to the root.

M.
Mar 21, 2013 at 9:23 PM
I added a webURL parameter, but it still returned the same error. I give up for today!
Thanks for all your efforts, Marc.

Don
Coordinator
Mar 21, 2013 at 9:30 PM
You'll get it.

M.