Welcome to Portal
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.
Requirement:
Customer would like to generate an invoice automatically once all the tasks ( associated to a Milestone) are closed.
We had accomplished this requirement using Custom functions. Create a connection for Zoho OAuth service with the scopes “Zohoprojects.projects.READ, ZohoBooks.projects.READ” to replace ‘books’ with the connection name in the below script. Click this link below to learn how to create the connection. It is possible to automate this process by associating the custom function to the Task Workflow Rules with the criteria as Task status is 'Closed'.
Script to be used::
projectsAPIEndPoint = "https://projectsapi.zoho.com/restapi";
booksAPIEndPoint = "https://www.zohoapis.com/books/v3";
getTaskMap = Map();
getTaskMap.put("milestone_id",milestoneId);
getTaskMap.put("status","notcompleted");
getTasks = invokeurl
[
url :projectsAPIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/tasks/"
type :GET
parameters:getTaskMap
connection:"books"
];
if(!getTasks.containKey("tasks"))
{
projectDetails = invokeurl
[
url :projectsAPIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/"
type :GET
connection:"books"
];
if(projectDetails.get("projects").get(0).containKey("other_service"))
{
financeProjectId = projectDetails.get("projects").get(0).get("other_service").get("finance_project_id");
booksDetails = invokeurl
[
url :booksAPIEndPoint + "/projects/" + financeProjectId
type :GET
connection:"books"
];
customerId = booksDetails.get("project").get("customer_id");
// create an invoice code goes here
organizationID = "798709062";
itemList = List();
taskMap = Map();
taskMap.put("milestone_id",milestoneId);
taskMap.put("status","completed");
getCompletedTasks = invokeurl
[
url :projectsAPIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/tasks/"
type :GET
parameters:taskMap
connection:"books"
];
for each tasks in getCompletedTasks.get("tasks")
{
// info tasks;
imap = Map();
imap.put("quantity",1);
imap.put("rate",tasks.get("rate"));
imap.put("name",tasks.get("name"));
imap.put("project_id",financeProjectId);
itemList.add(imap);
}
params = Map();
params.put("customer_id",customerId);
params.put("line_items",itemList);
info params;
response = invokeurl
[
url :"https://www.zohoapis.com/books/v3/invoices?organization_id=798709062"
type :POST
parameters:params.toString()
connection:"books"
];
info response;
response = zoho.books.createRecord("invoice",organizationID,params,"books");
info response;
}
}
return "success";
Creating custom functions in Zoho Projects is straightforward and well-documented. Zoho provides a range of built-in functions that you can use as a starting point, and you can also easily define your own functions using Zoho's scripting language, Deluge. Give it a try and see how it can save your time and boost your productivity!
Watch this space for more such custom function codes.
Subscribe to receive notifications from this topic.