Hello Everyone,
A custom function is a software code that can be used to automate a process and this allows you to automate a notification, call a webhook, or perform logic immediately after a workflow rule is triggered. This feature helps to automate complex tasks and calculations.
Let us consider the below use case from a customer -
Whenever a project is created, a tag should be automatically created based on the project name and must to associated with that project and all the tasks created in that project
We had accomplished this requirement using Custom functions at both Project & Task levels.
Create a connection for the Zoho Projects service with the scopes “zohoprojects.tags.ALL, zohoprojects.projects.READ” to replace ‘connectionprojects’ with the connection name. Click this link below to learn how to create the connection.
Script to be used at Task level
endPoint = "https://projects.zoho.com/restapi/portal/";
endPointV3 = "https://projects.zoho.com/api/v3/portal/";
tagIds = List();
getProjectResponse = invokeurl
[
url :endPoint + portalId + "/projects/" + projectId + "/"
type :GET
connection:"connectionprojects"
];
tagDetails = getProjectResponse.get("projects").get(0).get("TAGS");
for each tagDetail in tagDetails
{
tagIds.add(tagDetail.get("id"));
}
tagsParam = Map();
tagsParam.put("tag_id",toString(tagIds));
tagsParam.put("entity_id",taskId);
tagsParam.put("entityType","5");
url1 = endPointV3 + portalId + "/projects/" + projectId + "/tags/associate";
associateTagsResponse = invokeurl
[
url :url1
type :POST
parameters:tagsParam
connection:"connectionprojects"
];
return "success";
Script to be used at project level
url1 = "https://projects.zoho.com/api/v3/portal/" + portalId + "/tags";
tagObject = Map();
tagObject.put("name", projectName);
tagArray = List();
tagArray.add(tagObject);
tagParam = Map();
tagParam.put("tags",tagArray);
createTagResponse = invokeurl
[
url :url1
type :POST
parameters:tagParam
connection:"connectionprojects"
];
tagId = createTagResponse.get("tags").get(0).get("id");
tagsParam = Map();
tagsParam.put("tag_id",tagId);
tagsParam.put("entity_id",projectId);
tagsParam.put("entityType","2");
url1 = "https://projects.zoho.com/api/v3/portal/" + portalId + "/projects/" + projectId + "/tags/associate";
associateTagsResponse = invokeurl
[
url :url1
type :POST
parameters:tagsParam
connection:"connectionprojects"
];
return "success";