Get Numeric Id of Current Logged In User In SharePoint Using SPServices JQuery Library

In SharePoint Online, if we want to store the user details in the People or Group field, then we also required user numeric id which we can’t get from the SPServices provided function $().SPServices.SPGetCurrentUser.

The format required to store details in SharePoint Online People or Group field is:

'<Numeric User Id>;#i:0#.f|membership|<User Email Id>' i.e. '5002;#i:0#.f|membership| amitkumar@amitkumarmca04.blogspot.com’.

In order to get above mentioned details, we required  SPServices provided function called $().SPServices.GetUserInfo. 

Get current logged-in user numeric id using $().SPServices.GetUserInfo:

$().SPServices({
    operation: "GetUserInfo",
    async: false,
    userLoginName: $().SPServices.SPGetCurrentUser(),
    completefunc: function  (xData, Status) {
 
        $(xData.responseXML).find("User").each(function () {
            console.log($(this).attr("ID"));
            console.log($(this).attr("Name"));
            console.log($(this).attr("Email"));
            console.log($(this).attr("LoginName"));
        });
 
    }
});
/*
Output:
118
Amit Kumar
amitkumar@amitkumarmca04.blogspot.com 
i:0#.f|membership| amitkumar@amitkumarmca04.blogspot.com //--For SharePoint Online user
*/

With the help of above code block, you can get the numeric user id of current logged-in user and can prepare the value for People or Group field:
'118;#i:0#.f|membership|amitkumar@amitkumarmca04.blogspot.com’

Get numeric id of user using $().SPServices.GetUserInfo:

In the above code block, we tried to get the numeric id of logged-in in SharePoint online site, but in many cases we required to get the numeric id of individual user during some business operation. In those cases, we need to pass userLoginName of individual user in $().SPServices.GetUserInfo function as: 'i:0#.f|membership|amitkumarmca04.blogspot.com'

$().SPServices({
    operation: "GetUserInfo",
    async: false,
    userLoginName: 'i:0#.f|membership|amitkumarmca04.blogspot.com',
    completefunc: function  (xData, Status) {
 
        $(xData.responseXML).find("User").each(function () {
            console.log($(this).attr("ID"));
            console.log($(this).attr("Name"));
            console.log($(this).attr("Email"));
            console.log($(this).attr("LoginName"));
        });
 
    }
});
/*
Output:
118
Amit Kumar
amitkumar@amitkumarmca04.blogspot.com 
i:0#.f|membership| amitkumar@amitkumarmca04.blogspot.com //--For SharePoint Online user
*/

With the help of above code block, you can get the numeric user id of individual user and can prepare the value for People or Group field:
'118;#i:0#.f|membership|amitkumar@amitkumarmca04.blogspot.com’.