Power of Automation :: Invoice your timelogs automatically once the tasks are completed

Power of Automation :: Invoice your timelogs automatically once the tasks are completed

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. 


    • Sticky Posts

    • Accessibility Spotlight Series - 1

      Every user interacts with products differently, what feels intuitive to one may be challenging for another. Addressing this, accessibility is built into Zoho Project's design philosophy. This helps users navigate and perform actions with ease irrespective
    • Customize User Invites with Invitation Templates

      Invitation Templates help streamline the invitation process by allowing users to create customized email formats instead of sending a one-size-fits-all email. Different invitation templates can be created for portal users and client users to align with
    • Zoho Projects - Q3 Updates | 2025

      Hello Users, The final quarter of the year 2025 has begun, and we at Zoho Projects are all set with a plan. New targets to achieve and new milestones to reach, influenced by the lasting imprint of the past quarter. 2025's Q3 saw some new features and
    • Introducing Version-3 APIs - Explore New APIs & Enhancements

      Happy to announce the release of Version 3 (V3) APIs with an easy to use interface, new APIs, and more examples to help you understand and access the APIs better. V3 APIs can be accessed through our new link, where you can explore our complete documentation,
    • Schedule Exports for Regular Project Updates

      Tracking project data often means exporting data at regular intervals. Instead of manually exporting data every time, users can schedule exports for Phases, Tasks, and Tasks in Zoho Projects. These exports can be set to run once, daily, weekly, or monthly