Call a Function Recursively to Update Fields in Linked Records via Lookup | Zoho Creator Help

Call a Function Recursively to Update Fields in Linked Records via Lookup

Requirement

Implement a recursive function to update a series of linked records by iterating through the chain established via a lookup field.

Use case

Imagine a Zoho Creator task management application where task requests are categorized as either new or reinitiated. New tasks are created directly by entering task details in the Add Tasks form, while reinitiated tasks are linked to tasks that are previously On Hold. This link is achieved using a lookup field in the same form. This creates a chain of connected tasks, as reinitiated tasks can also be put on hold and reinitiated repeatedly. When the latest task in the chain is marked as Completed, a recursive function is triggered to traverse the chain via the lookup field, updating the status of all linked tasks, including the initial On Hold task, to Completed, ensuring accurate and consistent status updates across all related tasks.

Steps to follow

  1. Create a form with the following details to store task details.

    Form

    Form Link Name

    Field Type

    Field Name

    Field Link Name

    Add Task

    Add_Task

    Radio

    Task Category

    • New task

    • Reinitiate task on hold

    Task_Category

    Single Line

    Task Title

    Task_Title

    Look Up (Add_Task)

    Reinitiate Task

    Reinitiate_Task

    Drop Down

    Task Status

    • Started (Default)

    • On Hold

    • Reinitiated

    • Completed 

    Notes
    Note: Set the Started option as default by clicking the radio button near that choice in the field properties.

    Task_Status

  2. Click the set filter option in the field properties of the Reinitiate Task lookup field to configure filter to show only the tasks On Hold.

  3. Select the field as Task Status, Operator as equals, and Choices as On Hold.

  4. Create a Deluge function by selecting the return type as void and specifying an argument with the name Record_ID with int data type. Name the function "Recursion." This function will be triggered via workflow and called recursively to fetch and update the associated reinitiated task statuses.

  5. Add the following script in the Deluge editor.
    1. void Recursion(int Record_ID)
    2. {
    3. //Fetch records matching the record ID supplied in the argument.
    4. fetch_records = Add_Task[ID == Record_ID];
    5. //Update the task status in the fetched record as Completed.
    6. fetch_records.Task_Status="Completed";
    7. //Trigger the function again to fetch the associated reinitiated task and update its status as Completed.
    8. if(fetch_records.Task_Category == "Reinitiate task on hold")
    9. {
    10.        thisapp.Recursion(fetch_records.Reinitiate_Task);
    11. }
    12. }
  6. Create a workflow to execute on successful form submission of the Add Task form by selecting the Record Event as 'Created or Edited'. Name the workflow 'Update_Status' and click Create Workflow. This workflow will update the reinitated task's status and the associated tasks status.

  7. Click Add New Action > Deluge Script and add the following script in the deluge editor.
    1. //If an On Hold task is reinitiated, update the Task Status of the reinitiated task record and the associated On Hold.
    2. //On creating a new task record to reinitate a task On Hold.
    3. if(Task_Category == "Reinitiate task on hold" && Task_Status == "Started")
    4. {
    5. input.Task_Status = "Reinitiated";
    6. //Update the Task Title of the reinitiate task with the associated On Hold task's title.
    7. input.Task_Title = input.Reinitiate_Task.Task_Title;
    8. fetch_records = Task_Request[ID == input.Reinitiate_Task];
    9. fetch_records.Task_Status="Reinitiated";
    10. }
    11. //If an reinitiated task's status is marked as completed, Update all the trail of associated reinitiated task's record as 'Completed' by triggering the Recursion Custom Function.

    12. //On Changing the status of the reinitiated task to Completed.
    13. if(Task_Category == "Reinitiate task on hold" && Task_Status == "Completed")
    14. {
    15. //Call the Recursion function.
    16. thisapp.Recursion(input.ID);
    17. }

See how it works


  1. Call Function
  2. Fetch Records

      Create. Review. Publish.

      Write, edit, collaborate on, and publish documents to different content management platforms.

      Get Started Now


        Access your files securely from anywhere

          Zoho CRM Training Programs

          Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

          Zoho CRM Training
            Redefine the way you work
            with Zoho Workplace

              Zoho DataPrep Personalized Demo

              If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

              Zoho CRM Training

                Create, share, and deliver

                beautiful slides from anywhere.

                Get Started Now


                  Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                  BOOK A SESSION







                              Quick LinksWorkflow AutomationData Collection
                              Web FormsEnterpriseOnline Data Collection Tool
                              Embeddable FormsBankingBegin Data Collection
                              Interactive FormsWorkplaceData Collection App
                              CRM FormsCustomer ServiceAccessible Forms
                              Digital FormsMarketingForms for Small Business
                              HTML FormsEducationForms for Enterprise
                              Contact FormsE-commerceForms for any business
                              Lead Generation FormsHealthcareForms for Startups
                              Wordpress FormsCustomer onboardingForms for Small Business
                              No Code FormsConstructionRSVP tool for holidays
                              Free FormsTravelFeatures for Order Forms
                              Prefill FormsNon-Profit

                              Intake FormsLegal
                              Mobile App
                              Form DesignerHR
                              Mobile Forms
                              Card FormsFoodOffline Forms
                              Assign FormsPhotographyMobile Forms Features
                              Translate FormsReal EstateKiosk in Mobile Forms
                              Electronic Forms
                              Drag & drop form builder

                              Notification Emails for FormsAlternativesSecurity & Compliance
                              Holiday FormsGoogle Forms alternative GDPR
                              Form to PDFJotform alternativeHIPAA Forms
                              Email FormsFormstack alternativeEncrypted Forms

                              Wufoo alternativeSecure Forms

                              TypeformWCAG


                                          Create. Review. Publish.

                                          Write, edit, collaborate on, and publish documents to different content management platforms.

                                          Get Started Now




                                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                Manage your brands on social media


                                                                  • Desk Community Learning Series


                                                                  • Digest


                                                                  • Functions


                                                                  • Meetups


                                                                  • Kbase


                                                                  • Resources


                                                                  • Glossary


                                                                  • Desk Marketplace


                                                                  • MVP Corner


                                                                  • Word of the Day


                                                                  • Ask the Experts


                                                                    Zoho Sheet Resources

                                                                     

                                                                        Zoho Forms Resources


                                                                          Secure your business
                                                                          communication with Zoho Mail


                                                                          Mail on the move with
                                                                          Zoho Mail mobile application

                                                                            Stay on top of your schedule
                                                                            at all times


                                                                            Carry your calendar with you
                                                                            Anytime, anywhere




                                                                                  Zoho Sign Resources

                                                                                    Sign, Paperless!

                                                                                    Sign and send business documents on the go!

                                                                                    Get Started Now




                                                                                            Zoho TeamInbox Resources





                                                                                                      Zoho DataPrep Demo

                                                                                                      Get a personalized demo or POC

                                                                                                      REGISTER NOW


                                                                                                        Design. Discuss. Deliver.

                                                                                                        Create visually engaging stories with Zoho Show.

                                                                                                        Get Started Now








                                                                                                                            • Related Articles

                                                                                                                            • Configuring Deluge script on update in form workflows

                                                                                                                              Workflows will be triggered only upon manually editing the records (updating a field's value) in your reports i.e.,you need to open the respective form and edit the required field's value. This workflow will not be triggered upon updating a field's ...
                                                                                                                            • Update a form using custom action (from another form's report)

                                                                                                                              Requirement   Update a form using a custom action configured in another form's report. Use Case In an engineering college student management application, a student may withdraw at any time of the academic year. Whenever a student applies for ...
                                                                                                                            • Auto populate a field based on the selection from a lookup dropdown

                                                                                                                              Requirement   When a value is chosen from a lookup dropdown, related values are populated in the other fields of the same form. Use Case   An order management app contains a form to store order details. When the admin chooses the customer name from ...
                                                                                                                            • Generate Deluge Scripts Using Zia Assistance

                                                                                                                              Note: Generated scripts may not always be accurate, as is common with any AI. However, we are constantly refining it to maximize its reliability. Generated scripts are adaptive. The same prompt may generate different scripts at different times based ...
                                                                                                                            • Store records for 30 days after deletion

                                                                                                                              Requirement Deleted records must be stored for 30 days after deletion, after which they should be permanently removed from the database. Use Case A library management app is used to manage books, memberships, and other resources. When a membership is ...
                                                                                                                              Wherever you are is as good as
                                                                                                                              your workplace

                                                                                                                                Resources

                                                                                                                                Videos

                                                                                                                                Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                                eBooks

                                                                                                                                Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                                Webinars

                                                                                                                                Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                CRM Tips

                                                                                                                                Make the most of Zoho CRM with these useful tips.



                                                                                                                                  Zoho Show Resources