Welcome to Portal

?Unknown\pull-down

Welcome to Zoho Cares

Bienvenido a Soporte de Zoho

Search our knowledge base, ask the community or submit a request.

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

Helpful?00
Updated: 1 month ago
Share :