For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.
Zoho CRM: Using a function for validation rules (or restricting specific picklist options by user profile)

Zoho CRM: Using a function for validation rules (or restricting specific picklist options by user profile)

What?
So this is a pretty cool feature in Zoho CRM that I hadn't used much but definitely worth an article. The ability to block field picklist options from being selected based on the profile of a user.

Why?
There were several alternatives we considered beforehand which still didn't fit the requirement: A client's first-line agents would have a lead record with the status "New Lead". The client wanted that if the status had changed to something else, the first-line agent would not be allowed to set it back to "New Lead". Automations and workflows could however (run as Administrators). Mapping a dependency field didn't fit the bill because we want "Lead Status" to be displayed to the first-line agents. Making this field read-only to first-line agents also wouldn't help as some of the options should be selectable. Two separate fields weren't quite right either: 1 as read-only (permission only to higher level) and 1 picklist as selectable means that the first-line agent would be referring to 2 status fields and not really knowing which one defines the stage the lead is at.

How?
Well this can be done through a validation rule. After working in Zoho CRM for over 3 years, this is the first time I'm using it so I'm documenting it.

For this example, we're going to use my use-case scenario mentioned earlier: first-line agents can't select a specific option in the Lead Status picklist:

  1. Login to ZohoCRM > Setup > Customization > Modules and Fields > Leads
  2. Select "Validation Rules" and cick on "New Validation Rule"
  3. Choose the layout, this has to be the highest level (I think) as a custom lead layout didn't work
  4. Choose field to validate > Select "Lead Status"
  5. Choose validation type as "Validate using function" and click on "Next"
  6. For functions, select "Write your own"
  7. Give it a function name, eg. "fn_Validation_LeadStatusChange", a display name, eg. "Fn - Validation - Lead Status Change", and a description...
  8. You will be presented with a deluge IDE editor. I'm putting in the following code:
    copyraw
    /* *******************************************************************************
    Function:       fn_Validate_LeadStatusChange
    Trigger:        Function executed when a record is changed
    Inputs:         String crmAPIRequest
    Outputs:        output message to user
    
    Date Created:   2022-02-11 (JoelLipman.com - Joel Lipman)
                    - Initial release
                    - Checks the user profile of the logged-in user and allows the change or not
    ******************************************************************************* */
    // 
    // declare
    m_Output = Map();
    v_UserID = 0;
    v_UserProfile = "";
    l_DisallowedProfiles = List({"Agent"});
    l_DisallowedOptions = List({"New Lead","Appointment Booked","Lead Confirmed"});
    //
    // capture event
    m_Webhook = crmAPIRequest.toMap();
    //
    // check if user info is provided
    if(!isnull(m_Webhook.get("user_info")))
    {
    	//
    	// extract user ID
    	v_UserID = m_Webhook.get("user_info").get("id").toLong();
    }
    //
    // if user ID was extracted sucessfully
    if(v_UserID != 0)
    {
    	//
    	// get user details (we need the profile)
    	r_UserDetails = zoho.crm.getRecordById("users",v_UserID);
    	if(!isnull(r_UserDetails.get("users")))
    	{
    		for each  r_User in r_UserDetails.get("users")
    		{
    			if(!isnull(r_User.get("profile")))
    			{
    				v_UserProfile = r_User.get("profile").get("name");
    				break;
    			}
    		}
    	}
    }
    //
    // get field value that we want to check for
    v_LeadStatus = "";
    if(!isnull(m_Webhook.get("record")))
    {
    	//
    	// extract lead status
    	v_LeadStatus = ifnull(m_Webhook.get("record").get("Lead_Status"),"");
    }
    //
    // if user profile is not allowed to make this change
    m_Output.put("status","success");
    if(v_LeadStatus != "")
    {
    	if(l_DisallowedProfiles.contains(v_UserProfile) && l_DisallowedOptions.contains(v_LeadStatus))
    	{
    		m_Output.put("message","Your user profile does not allow you to change the lead status back to \"" + v_LeadStatus + "\"");
    		m_Output.put("status","error");
    	}
    }
    //
    // return response
    return m_Output;
    1.  /* ******************************************************************************* 
    2.  Function:       fn_Validate_LeadStatusChange 
    3.  Trigger:        Function executed when a record is changed 
    4.  Inputs:         String crmAPIRequest 
    5.  Outputs:        output message to user 
    6.   
    7.  Date Created:   2022-02-11 (JoelLipman.com - Joel Lipman) 
    8.                  - Initial release 
    9.                  - Checks the user profile of the logged-in user and allows the change or not 
    10.  ******************************************************************************* */ 
    11.  // 
    12.  // declare 
    13.  m_Output = Map()
    14.  v_UserID = 0
    15.  v_UserProfile = ""
    16.  l_DisallowedProfiles = List({"Agent"})
    17.  l_DisallowedOptions = List({"New Lead","Appointment Booked","Lead Confirmed"})
    18.  // 
    19.  // capture event 
    20.  m_Webhook = crmAPIRequest.toMap()
    21.  // 
    22.  // check if user info is provided 
    23.  if(!isnull(m_Webhook.get("user_info"))) 
    24.  { 
    25.      // 
    26.      // extract user ID 
    27.      v_UserID = m_Webhook.get("user_info").get("id").toLong()
    28.  } 
    29.  // 
    30.  // if user ID was extracted sucessfully 
    31.  if(v_UserID != 0) 
    32.  { 
    33.      // 
    34.      // get user details (we need the profile) 
    35.      r_UserDetails = zoho.crm.getRecordById("users",v_UserID)
    36.      if(!isnull(r_UserDetails.get("users"))) 
    37.      { 
    38.          for each  r_User in r_UserDetails.get("users") 
    39.          { 
    40.              if(!isnull(r_User.get("profile"))) 
    41.              { 
    42.                  v_UserProfile = r_User.get("profile").get("name")
    43.                  break; 
    44.              } 
    45.          } 
    46.      } 
    47.  } 
    48.  // 
    49.  // get field value that we want to check for 
    50.  v_LeadStatus = ""
    51.  if(!isnull(m_Webhook.get("record"))) 
    52.  { 
    53.      // 
    54.      // extract lead status 
    55.      v_LeadStatus = ifnull(m_Webhook.get("record").get("Lead_Status"),"")
    56.  } 
    57.  // 
    58.  // if user profile is not allowed to make this change 
    59.  m_Output.put("status","success")
    60.  if(v_LeadStatus != "") 
    61.  { 
    62.      if(l_DisallowedProfiles.contains(v_UserProfile) && l_DisallowedOptions.contains(v_LeadStatus)) 
    63.      { 
    64.          m_Output.put("message","Your user profile does not allow you to change the lead status back to \"" + v_LeadStatus + "\"")
    65.          m_Output.put("status","error")
    66.      } 
    67.  } 
    68.  // 
    69.  // return response 
    70.  return m_Output; 
  9. Click "Save" and Done!
Yields:
Alert advising user not permitted to change lead status

Additional Note(s):
  • If the user's profile is blank, the rule will not apply to them.
    copyraw
    l_Disallowed = List();
    l_Disallowed.add("Joel");
    if(l_Disallowed.contains(""))
    {
    	info "Yay";
    }
    else 
    {
    	info "Nay";
    }
    // yields "Nay"
    //
    v_DisallowedString = "Joel";
    if(v_DisallowedString.contains(""))
    {
    	info "Yay";
    }
    else 
    {
    	info "Nay";
    }
    // yields "Yay"
    //
    1.  l_Disallowed = List()
    2.  l_Disallowed.add("Joel")
    3.  if(l_Disallowed.contains("")) 
    4.  { 
    5.      info "Yay"
    6.  } 
    7.  else 
    8.  { 
    9.      info "Nay"
    10.  } 
    11.  // yields "Nay" 
    12.  // 
    13.  v_DisallowedString = "Joel"
    14.  if(v_DisallowedString.contains("")) 
    15.  { 
    16.      info "Yay"
    17.  } 
    18.  else 
    19.  { 
    20.      info "Nay"
    21.  } 
    22.  // yields "Yay" 
    23.  // 

Source(s):
Category: Zoho CRM :: Article: 340

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com