SharePoint 2010 use SPServices to get a users ID

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!