Hello Everyone,
A Custom function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it.
Requirement:
One of our customers wanted to update the Associated Team automatically based on the Task owner added.
For example, If User Alex is associated with both the Networking and Central IT Teams, making Alex as Task Owner will automatically update the Task with his Associated Teams. Similarly, when another user is added, their associated Teams will also be updated to the Tasks provided those Teams are part of the Project.
This can be implemented using Task custom functions along with Workflow rules.
Custom function code:
zuidList = list();
/* Get all owners and teams. */
for each owner in taskOwners
{
zuidList.add(owner.get("id").toString());
}
getTeamUsers = invokeurl
[
url :endPointV3 + portalId + "/teams/users"
type :GET
connection:"*XXXXX*"
];
if(getTeamUsers.get("page_info").get("count") > 0)
{
associtedTeams = list();
for each user in getTeamUsers.get("team_users")
{
info zuidList + " == " + user.get("zuid") + " : " + zuidList.contains(user.get("zuid"));
if(zuidList.contains(user.get("zuid")))
{
associtedTeams.addAll(user.get("associted_teams"));
}
}
associtedTeams = associtedTeams.distinct();
}
/* Get all associate teams */
getAssociatedTeams = invokeurl
[
url :endPointV3 + portalId + "/projects/" + projectId + "/teams"
type :GET
connection:"*XXXXX*"
];
// info getAssociatedTeams;
associteTeam = list();
for each teamid in associtedTeams
{
associteTeam.add({"id":teamid});
}
/* Remove teams that are already associated */
if(getAssociatedTeams.get("page_info").get("count") > 0)
{
for each team in getAssociatedTeams.get("teams")
{
if(associtedTeams.contains(team.get("id")))
{
associtedTeams.removeElement(team.get("id"));
}
}
}
// info associtedTeams;
/* Associate teams to project of not added */
if(associtedTeams.size() > 0)
{
params = Map();
params.put("team_ids",associtedTeams);
info params;
associateTeamToProject = invokeurl
[
url :endPointV3 + portalId + "/projects/" + projectId + "/associate-teams"
type :POST
parameters:params
connection:"*XXXXX*"
];
info associateTeamToProject;
}
/* Associate teams to task of not added */
if(associteTeam.size() > 0)
{
params = Map();
params.put("teams",{{"add":associteTeam}});
info params;
associateTeamToTask = invokeurl
[
url :endPointV3 + portalId + "/projects/" + projectId + "/tasks/" + taskId
type :PATCH
parameters:params.toString()
connection:"*XXXXX*"
];
info associateTeamToTask;
}
return "success";
Make sure to replace XXXXX with Zoho Projects connection link name along with scopes ZohoProjects.tasks.UPDATE, ZohoProjects.teams.ALL. Please find the screenshot of the list of parameters to be mapped for reference.
We hope you found this post useful. If you have any questions, feel free to share them in the comments below.