For Zoho Services only:


I'm actually part of a bigger team at Ascent Business Solutions where we have support technicians and project consultants. Support is for smaller technical fixes but this can include developments, reports or integrations; depending on the size of the task. Projects are for more time-consuming developments such as revamps of the Zoho Suite of apps or on-site training. The advantage of a team is that if I am out-of-office for a day or so, there is always someone at Ascent Business Solutions who can deal with any queries/issues you may have.

Our support rates can be found and purchased at http://ascentbusiness.co.uk/zoho-support-2. A support bundle doesn't have an expiry date. So whether we can do what you want within the bundle and a year later need further support, if there are minutes left on the bundle then there is no additional charge.

Our project rates for bigger developments can be found at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices and will involve a dedicated project consultant along with developers who will hold your hand through the development process.

If you want help building a solution for one of the Zoho Apps in the Zoho Suite, contact us on 0121 293 8140 (UK) or by email at info@ascentbusiness.co.uk. You can also visit our website at http://ascentbusiness.co.uk.

I regularly build and specialize in 2-way API integrations for Xero, Shopify and eBay.

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: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used 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 - Valid till 8 May 2022 bc1qjtp4l4ra452wzvuk9a45yfj82zkahsyy2z379y
© 2022 Joel Lipman .com. All Rights Reserved.