Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharePoint 2010 use SPServices to get a users ID

I'm using SharePoint with the SPServices jQuery library, and I'm making use of the SPGetCurrentUser function. However, it seems it just returns the login user name without the ID. Example:

DOMAIN\user

I need the whole account name with ID:

1;#DOMAIN\user

If there's a way just to return the ID I can concatenate the two together. But I can't find it.

Ultimately I'm trying to assign a list item to the current user. If there's a way to do this without the ID I'm open to that possibility as well. Thanks!

like image 807
skinneejoe Avatar asked Apr 04 '11 17:04

skinneejoe


2 Answers

Ok I figured it out:

$().SPServices({
    operation: "GetUserInfo",
    async: false,
    userLoginName: $().SPServices.SPGetCurrentUser(),
    completefunc: function (xData, Status) {
        $(xData.responseXML).find("User").each(function() {
            curUserId = $(this).attr("ID");
            curUserName = $(this).attr("Name");
            curFullUserName = $(this).attr("ID")+";#"+$(this).attr("Name");
        });
    }
});

This little function will create three vars:

  • curUserId = the current users ID (Ex: 1)
  • curUserName = the current users Name (Ex: DOMAIN\user)
  • curFullUserName = the ID and Name combined in SP format (Ex: 1;#DOMAIN\user)

Hope it helps!

like image 124
skinneejoe Avatar answered Nov 06 '22 11:11

skinneejoe


You can try:

 $().SPServices.SPGetCurrentUser({
        fieldName: "ID"
    });
like image 45
vvk Avatar answered Nov 06 '22 10:11

vvk