Creating roll ups on custom_fields

Creating roll ups on custom_fields

portalId = 60XXXXXX;
// projectId = 19063XXXXXXX;
// taskid = 19063XXXXXXX;
response = zoho.projects.getRecordById(portalId,projectId,"tasks",taskid,"bs");
// info response;
tasks = response.get("tasks").get(0);
info tasks.get("id");
p_task_id = tasks.get("parent_task_id");
info "task_parent" + p_task_id;
custom_fields = tasks.get("custom_fields");
for each  custom_field in custom_fields
{
if(custom_field.get("label_name") == "Actual_Cost")
{
task_amount_act = ifnull(custom_field.get("value").toDecimal(),0);
// Convert value to decimal
// actual_cost_l1 = actual_cost_l1 + task_actual_cost;
info "task_amount_act >>" + task_amount_act;
}
}
p_task_res = zoho.projects.getRecordById(portalId,projectId,"tasks",p_task_id,"bs");
tasks_p = p_task_res.get("tasks").get(0);
tasks_p_id = tasks_p.get("id");
info "P_t_id :" + tasks_p_id;
custom_fields_p = tasks_p.get("custom_fields");
for each  custom_field in custom_fields_p
{
if(custom_field.get("label_name") == "Actual_Cost")
{
task_actual_cost = ifnull(custom_field.get("value").toDecimal(),0);
// Convert value to decimal
// actual_cost_l1 = actual_cost_l1 + task_actual_cost;
info "task_actual_cost >>" + task_actual_cost;
}
}
total_sum_st_l1 = task_actual_cost + task_amount_act;
total_sum_dis = total_sum_st_l1.toLong();
info "total_sum_st_l1>>" + total_sum_dis;
task_details = Map();
ts = Map();
ts.put("UDF_LONG10",total_sum_dis);
task_details.put("custom_fields",ts);
res = zoho.projects.update(portalId,projectId,"tasks",tasks_p_id,task_details,"bs");
info "res >>" + res;
return "";

This script is designed to aggregate the value of a custom field (e.g., "Actual Cost") from a subtask and add it to the corresponding custom field of its parent task. The workflow can be extended by implementing a rule that triggers this script whenever the subtask's custom field is updated.

Key Considerations:

  • Single Update Application: This script is intended for scenarios where the custom field value is updated once. If the field is subject to frequent updates, additional logic may be required to ensure accurate aggregation.
  • Custom Field Handling: When updating values in custom fields, it is crucial to verify the field type and format the input accordingly. You can determine the field type by inspecting the task's page.

Code Workflow:

  1. Retrieve Subtask Details:

    • Fetches the subtask details using getRecordById.
    • Extracts the custom field value for "Actual Cost."
  2. Retrieve Parent Task Details:

    • Fetches the parent task details using getRecordById.
    • Extracts the custom field value for "Actual Cost."
  3. Calculate Total Cost:

    • Sums the "Actual Cost" values from the subtask and the parent task.
  4. Update Parent Task:

    • Updates the parent task's custom field with the aggregated cost.

This script provides a foundational approach, allowing you to tailor the logic according to your specific requirements.

    Access your files securely from anywhere

        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

                                              • Tip of the Week: Task Sorting

                                                I believe that sorting of tasks helps managing the activities in a better fashion. You might second it too . By default, the tasks are listed chronologically. However, you can sort the tasks either by its title, start date, end date, priority, created by and percentage completion. All you have to do is, click the Task Sorting option and select the required criteria. Few points to be noted about task sorting: This option is available in the Classic View only (within My Tasks, Tasks & Milestones section).
                                              • Tip # 3 - Follow And Add Followers To Your Project Modules

                                                Besides owning effective managers and quick-witted employees, you need to have supportive followers for accomplishing your project goals. Accompanying this note, today, lets run through a quick and easy tip on  'How to follow and add followers to your project activities?' . Follow the project activities all by yourself -Follow to get real-time milestone updates Milestones are nothing but your project goals, which can ultimately uplift your projects' quality to the next level. Now, users in the portal
                                              • Tip of the Week: Task Dependency (Duration in Hours)

                                                I hope the tip on task dependency helped in understanding how it works in Zoho Projects. In a real-time, the successor task may or may not start on the predecessor's completion date. On either case, a project management tool should allow the users to set dependency between tasks. Ain't it? In Zoho Projects, the Task Duration in Hours option allows the users to set dependency between tasks that ends and starts on the same day. The Portal Owner and Admin role users can activate this option from the
                                              • Tip of the Week: Task Dependency

                                                Task Dependency - a feature that allows the users to establish dependency / linking between tasks within the project. Points to be noted with respect to this feature: Task Dependency can be set only from the Dependency View section within the Tasks & Milestones module Tasks setup with duration (start & end date) will only be displayed in the Dependency View The supported dependency model is Finish to Start Dependency can be established only between the tasks in the same project A task can be dependent
                                              • Tip of the Week: Drag and Drop option in Calendar

                                                As the thoughts flow in your mind, you plan the tasks, provide duration and assign users. While you go through the calendar later, you feel that a couple of tasks should needs to be postponed by a couple of days. Do you navigate to the Tasks & Milestones section and change the task duration? is the question I have for you. In case of YES, I would say that the task duration can be changed from the Calendar module itself. All you need to do is: Drag the task bar and Drop it on the required date. Note:


                                              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 Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • 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