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()"); } } }
- 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;
- // 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;
- // 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;