Dynamically Update Picklist Values in Zoho CRM Workflows
Hello all!
Welcome back to another interesting Kaizen post.
Today, we will discuss how to add automatically or remove values from a picklist field using Deluge within a workflow. This post serves as a solution for the
forum post.
Use case
The sales team migrates users from Pipedrive to Zoho CRM. In Pipedrive, the team managed deals using a Kanban view displayed based on the Closing Months (a picklist field). They automated the updating of picklist values to include current and upcoming months based on the deals' closing timelines.
In Zoho CRM, to replicate this process, users should manually update the picklist values. The requirement is to automate updating the picklist options during record creation or editing within a workflow.
Solution
By triggering the
PATCH Fields API (introduced in
V6) through a Deluge function within a workflow, this process can be easily automated. Automating picklist updates saves time, reduces the chances of human error, and ensures that picklist values are always up-to-date.
- First, create a custom picklist field called "Closing Month" in the Deals module.
- Then, use the custom picklist along with the Closing Date (a mandatory field date field in the Deals module) within a Deluge function in the Workflow.
- The PATCH Fields API can be used within the Deluge function to automate updating picklist values and to list the current and upcoming closing dates in deals.
Let us see the steps in detail on how to achieve this case.
Example
Consider the Closing Month as a custom picklist in the Deals module with three months: January, February, and March. Whenever a new deal is created and its closing month matches one of the picklist values, the record will be updated with the corresponding month in the Closing Month field and placed under the existing picklist value in the Kanban view. If the new closing month is not already in the picklist values, then the Deluge function will automatically create a new picklist value, and the record will fall under the new picklist value section in the Kanban view.
Follow the steps below to achieve our case in Zoho CRM:
- Create a Custom Picklist Field in the Deals module.
- Set Up a Workflow.
- Add a Deluge Function within a workflow.
- Configure the Workflow.
- Go to Setup > Customization > Modules and Fields.
- Select the Deals module and the desired layout where you want to add the picklist.
- Click on New Fields and then Add New Field.
- Select Picklist as the field type, name it "Closing Month", and add a list of months (In this post, only three months have been added for example purposes).
- Click Done to save the new picklist field.
- Navigate to Setup > Automation > Workflow Rules.
- Click on Create Rule, select the Deals module, and name the workflow in the Rule Name.
- Set the rule to trigger on record creation or update.
The workflow triggers based on the value of the Closing Date in the Deals module, executing the function when the Closing Date is not empty.
3. Add a Deluge Function within a workflow
You can either create a custom function or you can associate an existing one. Below is the Deluge code used within the workflow.
- //To map months with Numbers
- month = {1:"Jan",2:"Feb",3:"Mar",4:"Apr",5:"May",6:"June",7:"Jul",8:"Aug",9:"Sep",10:"Oct",11:"Nov",12:"Dec"};
- //To retrieve the Deal record
- dealRecord = zoho.crm.getRecordById("Deals",dealRecordID);
- info dealRecord;
- //To retrieve the Closing Date
- closingDate = dealRecord.get("Closing_Date");
- info closingDate;
- //To get the predefined value from the closing month
- closingMonth = month.get(closingDate.month());
- closingYear = closingDate.year();
- //To Format the Month and Year from the Closing Date
- picklistValue = closingMonth + " " + closingYear;
- info picklistValue;
- //Retrieving Current Picklist Values
- Dealsfield = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v7/settings/fields/5725767000003664513?module=deals"
- type :GET
- connection:"zohocrm"
- ];
- info Dealsfield;
- picklistValues = Dealsfield.get("fields").get(0).get("pick_list_values");
- info picklistValues;
- //Checking if the Picklist Value Already Exists
- flag = false;
- for each option in picklistValues
- {
- if(option.get("display_value").equals(picklistValue))
- {
- flag = true;
- info flag;
- }
- }
- //Adding a New Picklist Value if It Doesn't Exist
- if(flag == false)
- {
- requestBody = Map();
- requestList = List();
- requestData = Map();
- picklist = list();
- picklistobj = Map();
- picklistobj.put("display_value",picklistValue);
- picklist.add(picklistobj);
- requestData.put("pick_list_values",picklist);
- requestList.add(requestData);
- requestBody.put("fields",requestList);
- info requestBody + "";
- updateField = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v7/settings/fields/5725767000003664513?module=deals"
- type :PATCH
- parameters:requestBody + ""
- connection:"zohocrm"
- ];
- info updateField;
- }
- //To update the Deal Record
- requestBody = Map();
- requestList = List();
- requestData = Map();
- requestData.put("Closing_Month",picklistValue);
- requestList.add(requestData);
- requestBody.put("data",requestList);
- info requestBody + "";
- dealreecordUpdate = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v7/Deals/" + dealRecordID
- type :PUT
- parameters:requestBody + ""
- connection:"zohocrm"
- ];
- info dealreecordUpdate;
4. Configure the Workflow
Create a custom function by clicking the New Function or associate an existing one to the workflow. In our case, the deluge program has already been written and configured (associated) to the workflow.
- Under the workflow actions, select Function and choose the function you created.
- Ensure that the function is set to run when the workflow is triggered.
Creating a Deal with a Closing Date of January 2nd (Using an Existing Picklist Value)
Creating a Deal with a Closing Date of April 1st (Adding a New Picklist Value)
The new picklist value, which was not a value previously, has now been added to the picklist.
Hence, by using the
PATCH Field API, you can
add or
remove values from the
picklist.
Cheers!!!
Related Links
Additional Links
Zoho Desk Resources
-
Desk Community Learning Series
-
-
-
-
-
-
-
-
-
Zoho CRM Plus Resources
Zoho Books Resources
Zoho Subscriptions Resources
Zoho Projects Resources
Zoho Sprints Resources
Zoho Orchestly Resources
Zoho Creator Resources
Zoho WorkDrive Resources
Zoho Campaigns Resources
Zoho CRM Resources
Writer Get Started. Write Away!
Writer is a powerful online word processor, designed for collaborative work.