Zoho Deluge - Get Current User ID

What?
This is a quick article on different ways to get the current user ID in Zoho through code.

How?
I'm not a fan of method #1 but I only started developing in Zoho recently when API v1 was already being deprecated (end of life at the end of this year). So I'm familiar with the methods in API v2 or just using newer functions.

Method #1: API v1
userResp = getUrl(("https://crm.zoho.com/crm/private/xml/Users/getUsers?authtoken=xxxxxxxxxxx&scope=crmapi&type=ActiveUsers"));
users = userResp.executeXPath("/users/user");
if ((users != null) && (users != ""))
{
    userList = users.toList("-|-");
    for each user in userList
    {
        emailNode = user.executeXPath("/user/@email");
        email = emailNode.executeXPath("/email/text()");
        if (email == zoho.loginuserid)
        {
            idNode = user.executeXPath("/user/@id");
            id = idNode.executeXPath("/id/text()");
        }
    }
}

Method #2: InvokeConnector
// get current user id
m_UserTypes = Map();
r_Response = zoho.crm.invokeConnector("crm.getusers",m_UserTypes);
l_Users = ifnull(r_Response.get("response").get("users"), {});
v_CurrentUserID=0;
for each  r_User in l_Users
{
    if(r_User.get("email")==zoho.loginuserid)
    {
        v_CurrentUserID = r_User.get("id");
    }
}
info v_CurrentUserID;

Method #3: getRecords("users")
// get current user id
m_UserTypes = Map();
r_Response = zoho.crm.getRecords("users");
l_Users = ifnull(r_Response.get("users"), {});
v_CurrentUserID=0;
for each  r_User in l_Users
{
    if(r_User.get("email")==zoho.loginuserid)
    {
        v_CurrentUserID = r_User.get("id");
    }
}
info v_CurrentUserID;

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.