Function-17: Auto-update tasks with details from related record modules.

Function-17: Auto-update tasks with details from related record modules.



Welcome back everyone!

Last week, we learnt how to send automatic updates on deal progression by stage to all Contact Roles. This week, let's look at a custom function that fetches record details from related CRM modules right inside the task records..

Business scenario:

Tasks in Zoho CRM helps organize your to-do-lists efficiently. It not only helps keep a tab on your to-do-lists, but also enables easy access to related record in other modules. This for sure, makes you productive. What if I say there is a possibility of taking this one step ahead? While Tasks enables easy access to related records associated with the task records, won’t it be great if it were to fetch all the required information from the related record modules to complete the task?

Such a possibility cuts down on the need to loop between the task record and the related record module - say for example between the lead record and the associated task record. This week’s custom function helps you do just that. It auto-updates the custom fields in task records with required details from the related record modules.

Pre-requisites:

  • As custom functions are module specific, you need to update the appropriate custom function individually for the respective modules that require the auto-update functionality. We have covered four use cases with certain important fields in the below code. For instance, the code shared for Leads module auto-updates the State and Phone number details from the Leads module on the task record's custom fields. Choose the ones that fits your sales process and update the required field parameters accordingly.
  • Add the required custom fields in the Tasks Layouts. Go to Setup > Customization > Module and Fields > Tasks > Layouts , drag and drop the required custom fields. The details fetched from the respective record modules gets updated in these custom fields. 
Getting started with the custom function:

  1. Go to Setup > Automation > Actions > Custom Functions > Configure Custom Function > Write your own .
  2. Provide a name for the button. For example: “Auto update tasks.”. Add a description(optional).
  3. Choose the module as " Tasks ".
  4. Click “ Free flow scripting ”.
  5. Copy the code given below.
  6. Click “ Edit arguments ”.
  7. Enter the name as “ taskId ” and select the value as “ Task Id ”.
  8. Save the changes.
The script:

Code for Version 2.0 API:
 
taskDetails = zoho.crm.getRecordById("Tasks", input.taskId.toLong());
//info taskDetails;
whatid = ifnull(taskDetails.get("What_Id"),"");
whoid = ifnull(taskDetails.get("Who_Id"),"");
if( whatid != "")
{
recordid = ifnull(taskDetails.get("What_Id"),"").get("id")''
module = ifnull(taskDetails.get("se_module"),"");
getDetails = zoho.crm.getRecordById(module, whatid);
timezone = ifnull(getDetails.get("Time_Zone"),"");
mp=map();
mp.put("Time_Zone",timezone);
update = zoho.crm.update("Tasks", taskId, mp);
info mp;
info update;
}
if( whoid != "")
{
contid = ifnull(taskDetails.get("Who_Id"),"").get("id");
getDetails = zoho.crm.getRecordById("Contacts", contid);
timezone = ifnull(getDetails.get("Time_Zone"),"");
mp=map();
mp.put("Time_Zone",timezone);
update = zoho.crm.update("Tasks", taskId, mp);
info mp;
info update;
}

Code for Version 1.0 API:

1) Update Tasks from Leads :

taskIdStr=input.taskId.toString();
taskDetails = zoho.crm.getRecordById("Tasks", input.taskId);
module = ifnull(taskDetails.get("SEMODULE"),"");
id = ifnull(taskDetails.get("RELATEDTOID"),"");
if ( module == "Leads")
{
leadDetails = zoho.crm.getRecordById(("Leads"), id.toLong());
mp=map();
mp.put("State",ifnull(leadDetails.get("State"),""));
mp.put("Phone",ifnull(leadDetails.get("Phone"),""));
update=zoho.crm.updateRecord("Tasks", taskIdStr, mp);
info mp;
info update;
}

2) Update Tasks from Contacts :

taskIdStr = input.taskId.toString();
taskDetails = zoho.crm.getRecordById("Tasks", input.taskId);
contid = ifnull(taskDetails.get("CONTACTID"),"");
if ( contid != "")
{
contDetails = zoho.crm.getRecordById("Contacts", contid.toLong());
contmap = map();
contmap.put("Title", ifnull(contDetails.get("Title"),""));
contupdate = zoho.crm.updateRecord("Tasks", taskIdStr, contmap);
info contmap;
info contupdate;
}

3) Update Tasks from Solutions :

taskIdStr = input.taskId.toString();
taskdetails = zoho.crm.getRecordById("Tasks", input.taskId);
module = ifnull(taskdetails.get("SEMODULE"),"");
id = ifnull(taskdetails.get("RELATEDTOID"),"");
if ( module == "Solutions")
{
solutionsDetails = zoho.crm.getRecordById(("Solutions"), id.toLong());
mp=map();
mp.put("Subject",ifnull(solutionsDetails.get("Solution Title"),""));
mp.put("SMOWNERID",ifnull(solutionsDetails.get("SMOWNERID"),""));
mp.put("Description",ifnull(solutionsDetails.get("Additional Information"),""));
mp.put("Due Date", ifnull(solutionsDetails.get("Deadline Date"),""));
update=zoho.crm.updateRecord("Tasks", taskIdStr, mp);
}

4) Update Tasks from Accounts :

taskIdStr = input.taskId.toString();
taskDetails = zoho.crm.getRecordById("Tasks", input.taskId);
module = ifnull(taskDetails.get("SEMODULE"),"");
id = ifnull(taskDetails.get("RELATEDTOID"),"");
if ( module == "Accounts")
{
acctDetails = zoho.crm.getRecordById("Accounts", id.toLong());
acctmap = map();
acctmap.put("SQFT", ifnull(acctDetails.get("SQFT"),""));
acctmap.put("Lease Commencement", ifnull(acctDetails.get("Lease Commencement"),""));
acctmap.put("Termination Date", ifnull(acctDetails.get("Termination Date"),""));
acctmap.put("Lease Expiration", ifnull(acctDetails.get("Lease Expiration"),""));
acctupdate = zoho.crm.updateRecord("Tasks", taskIdStr, acctmap);
info acctmap;
info acctupdate;
}

--------------------------------------------------------------------------------------------------------------------------

Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful.

Do check out other custom functions shared in this series here.

See you all next week with another interesting custom function. Ciao!

Update: As you must be aware, API V1.0 will be deprecated and support for version 1.0 API will be available only till Dec 31, 2018. Version 1.0 compatible Functions will continue to work until Dec 31, 2019. You're advised to migrated to API Version 2.0 at the earliest. Check this announcement for more. We've updated the post to include the Version 2.0 compatible Function.

    Zoho Developer Community






                              Zoho Desk Resources

                              • Desk Community Learning Series


                              • Digest


                              • Functions


                              • Meetups


                              • Kbase


                              • Resources


                              • Glossary


                              • Desk Marketplace


                              • MVP Corner


                              • Word of the Day



                                  Zoho Marketing Automation
                                          • Sticky Posts

                                          • ZUG (Zoho User Group) In-person Meetups - Learn, Share, and Discuss All Things Zoho

                                            Hi, We hope you are all doing well. We are excited to announce the second leg of our in-person Zoho User Group (ZUG) meetups in your region. A quick update: Our first leg of meetups in 2024 reached completion, and Zoho experts had the opportunity to meet
                                          • Tip #35 - On using Kanban View in Zoho CRM

                                            Hi folks,  It's that time of the week again, and I am back with a quick tip about using Kanban View in Zoho CRM. If you think you missed any of our previous weeks' tips, you can read them here.  Tip #35 - On using Kanban View in Zoho CRM You deal with so many records in CRM every single day! When you click open each module in Zoho CRM, you have hundreds of records, each in various stages of your sales pipeline. Wouldn't it be cool if you had them all sorted automatically without having to filter
                                          • ZUG (Zoho User Group) In-person Meetups - Learn, share and discuss all things Zoho

                                            Hi, Hope you all are well. We're excited to announce our second leg of in-person Zoho User Group (ZUG) meetups in your region. A quick update - Our first leg of meetups in 2024 progressed and reached completion smoothly, where Zoho experts had the opportunity
                                          • ZUG (Zoho User Group) In-person Meetups - Learn, share and discuss all things Zoho

                                            A big warm hello to the Zoho Community, and Happy new year to all of you! We're thrilled to let you know that our ZUG Meetups for 2024 have almost begun, and we can't wait for you to be a part of them. We have some interesting topics in store for this
                                          • Cloning Email Templates across modules in Zoho CRM.

                                            The option of cloning email templates across modules has been a long standing feature request from the Community. Thank you all for being so patient with us. We are happy to inform you all that this enhancement has been rolled out. Just in case you haven't noticed it already, cloning email templates is possible now! Cloning is useful because it cuts down the hassle of having to create the same email templates again for different modules. Here are the steps: Navigate to Settings---> Customization--->Templates


                                          Manage your brands on social media



                                                Zoho TeamInbox Resources

                                                  Zoho DataPrep Resources



                                                    Zoho CRM Plus Resources

                                                      Zoho Books Resources


                                                        Zoho Subscriptions Resources

                                                          Zoho Projects Resources


                                                            Zoho Sprints Resources


                                                              Qntrl Resources


                                                                Zoho Creator Resources


                                                                  Zoho WorkDrive Resources



                                                                    Zoho Campaigns Resources

                                                                      Zoho CRM Resources

                                                                      • CRM Community Learning Series

                                                                        CRM Community Learning Series


                                                                      • Tips

                                                                        Tips

                                                                      • Functions

                                                                        Functions

                                                                      • Meetups

                                                                        Meetups

                                                                      • Kbase

                                                                        Kbase

                                                                      • Resources

                                                                        Resources

                                                                      • Digest

                                                                        Digest

                                                                      • CRM Marketplace

                                                                        CRM Marketplace

                                                                      • MVP Corner

                                                                        MVP Corner

                                                                      





                                                                      




                                                                          Design. Discuss. Deliver.

                                                                          Create visually engaging stories with Zoho Show.

                                                                          Get Started Now