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.

Hello Everyone,
 
A Custom Function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as to when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it. 

We have compiled a gallery of the most frequently solved use cases for Issues custom functions. You can access the same using the steps available in this link.        

And, today I would like to highlight one of the Gallery custom functions - Complete associated tasks once all issues are closed
 
Use case:-

This function marks all the associated tasks as completed once all related issues are closed.

Custom function code:-

Create a connection for the Zoho Projects service with the scopes "ZohoProjects.bugs.READ, ZohoProjects.tasks.UPDATE,ZohoProjects.projects.READ". Replace 'xxxxxxxxx' with the connection link name.

Click this link below to learn how to create the connection. Attached a screenshot for Arguments to be used.
projectsDomain = "https://projectsapi.zoho.com";
getAssociatedTasksUrl = projectsDomain + "/api/v3/portal/" + portalId + "/projects/" + bugProjectId + "/bugs/" + bugId + "/associated-tasks";
getAssociatedTasksParam = Map();
getAssociatedTasksParam.put("sindex","0");
getAssociatedTasksResp = invokeurl
[
url :getAssociatedTasksUrl
type :GET
parameters:getAssociatedTasksParam
connection:"xxxxxxxxxx"
];
info getAssociatedTasksResp;
if(getAssociatedTasksResp != null && getAssociatedTasksResp.get("task_array") != null)
{
getTaskLayoutUrl = projectsDomain + "/restapi/portal/" + portalId + "/projects/" + bugProjectId + "/tasklayouts";
taskLayoutDetails = invokeurl
[
url :getTaskLayoutUrl
type :GET
connection:"xxxxxxxxxx"
];
info taskLayoutDetails;
info "-------------------------------------";
statusNamevsIdMap = Map();
if(taskLayoutDetails != null && taskLayoutDetails.get("status_details") != null)
{
statusDetails = taskLayoutDetails.get("status_details");
for each  status in statusDetails
{
statusNamevsIdMap.put(status.get("name"),status.get("id"));
}
}
info "Status NamevsId Map: " + statusNamevsIdMap;
taskArrays = getAssociatedTasksResp.get("task_array");

if(statusNamevsIdMap.get(statusName) != null)
{
for each  taskObj in taskArrays
{
taskId = taskObj.get("TID");
criteriaObj = Map();
criteriaObj.put("cfid","48");
criteriaObj.put("criteria_condition","is");
criteriaObj.put("value",{taskId});
filterCriteria = Map();
filterCriteria.put("criteria",{criteriaObj});
filterCriteria.put("pattern","1");
getTaskAssociatedIssuesParam = Map();
getTaskAssociatedIssuesParam.put("index","0");
getTaskAssociatedIssuesParam.put("range","25");
getTaskAssociatedIssuesParam.put("sort_by","CREATED_TIME");
getTaskAssociatedIssuesParam.put("is_ascending","false");
getTaskAssociatedIssuesParam.put("filter",filterCriteria);
getTaskAssociatedIssuesUrl = projectsDomain + "/restapi/portal/" + portalId + "/projects/" + bugProjectId + "/module/bugs/view/48/";
getTaskAssociatedIssuesRes = invokeurl
[
url :getTaskAssociatedIssuesUrl
type :GET
parameters:getTaskAssociatedIssuesParam
connection:"xxxxxxxxxx"
];
info getTaskAssociatedIssuesRes;
bugEntities = getTaskAssociatedIssuesRes.get("data").get("0").get("entities");
completeTask = true;
for each  bug in bugEntities
{
if(!bug.get("is_completed"))
{
completeTask = false;
break;
}
}
if(completeTask)
{
updateTaskParameter = Map();
updateTaskParameter.put("custom_status",statusNamevsIdMap.get(statusName));
info "updateTaskParameter: " + updateTaskParameter;
taskDetails = zoho.projects.update(portalId,bugProjectId,"Tasks",taskId,updateTaskParameter,"xxxxxxxxxx");
info taskDetails;
}
}
}
}
We hope you found this post useful. If you have any questions, feel free to share them in the comments below.

Attachments
Arguments.png
Arguments.png72 KB
Reply
Reply to Harshini DaraA
/* */
  • 12
  • Insert
  • Plain text
Add Comment
(Up to 20 MB )