For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at http://ascentbusiness.co.uk/zoho-support-2.  For larger projects, check our bespoke pricing structure and receive dedicated support from our hands-on project consultants and developers at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at http://ascentbusiness.co.uk.

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 :: Article: 805

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

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 bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.