Hello Everyone,
Here we are again with another requirement that was fulfilled utilizing the Task custom functions.
Custom function code:
endPointV3 = "https://projects.zoho.com/api/v3/portal/";
milestoneStatusIds = List();
milestoneStatusNames = List();
milestoneParameter = Map();
// Get milestone layout details
milestoneLayoutDetails = invokeurl
[
url :endPointV3 + portalId + "/projects/" + projectId + "/milestones/layouts"
type :GET
connection:"xxxxxxxxxx"
];
milestoneCustomFieldDetails = milestoneLayoutDetails.get("section_details").get(0).get("customfield_details");
for each milestoneCustomFieldDetail in milestoneCustomFieldDetails
{
if(milestoneCustomFieldDetail.get("api_name").equalsIgnoreCase("status"))
{
milestoneStatusIds = milestoneCustomFieldDetail.getJSON("picklist_details");
milestoneStatusNames = milestoneCustomFieldDetail.getJSON("picklist_valuemap");
}
}
// Milestone re-open status id
indexOfReopen = milestoneStatusNames.indexOf("Reopen");
// Get milestone details
milestoneResponse = zoho.projects.getRecordById(portalId,projectId,"milestones",milestoneId,"xxxxxxxxxx");
if(milestoneResponse.containKey("milestones"))
{
milestoneStatusId = milestoneResponse.get("milestones").get(0).get("status_det").get("id");
}
else
{
return "Couldn't update status of none milestone";
}
if(milestoneStatusId != milestoneStatusIds.get(indexOfReopen))
{
milestoneParameter = Map();
milestoneParameter.put("milestone_ids",{"" + milestoneId + ""});
milestoneParameter.put("update_fields",{"CUSTOM_STATUSID":"" + milestoneStatusIds.get(indexOfReopen) + ""});
updateMilestoneDetails = invokeurl
[
url :endPointV3 + portalId + "/projects/" + projectId + "/milestones/" + milestoneId + "/updatefieldvalue"
type :POST
parameters:toString(milestoneParameter)
connection:"xxxxxxxxxx"
];
}
return "success";
Make sure to replace xxxxxxxxxx in the above code with the connection name. Screenshot of the list of parameters to be mapped is attached for reference.
By utilising the custom function provided above, we have embraced automation as an alternative to manually adjusting the Milestone's status to "Re-open."