Custom Functions | Administrator Guide 5.0 | Zoho People help

Custom Functions - Zoho People

What is a Custom Function?

Custom functions in Zoho People help simplify complex, multi-step actions through program scripts that you can write and execute. Custom functions helps in workflow automation where procedural logic is required, which cannot be implemented with the default actions such as, Alerts/Tasks/WebHooks, etc. With custom functions, you can automatically update the data in the related Zoho People records or third-party applications by executing simple program scripts.

Custom functions are written using Zoho's Deluge scripting language to effectively manipulate data, communicate with third-party applications and update responses. The script will run whenever a Workflow trigger events occurs.
Info
For more information about Deluge scripting language, refer to Zoho - Deluge Scripting Language.
Idea
Custom Function for a service can be created in Settings > Select a Service > Automation > Actions > Custom Functions.

How Custom Function works in Zoho People

  1. Create a Custom Function for a form in a service and associate it with a new or existing Workflow.
  2. Whenever a Workflow trigger event occurs, the Custom Function executes, performing the specified actions as defined in your code.

Create Custom Function

To create a custom function:
  1. From you home page, navigate to Settings > Select a Service > Automation > Custom Functions.

  2. Click Add Custom Function.
  3. Select the form for which you would like to create Custom Function.
  4. Enter a name for the Custom Function.
  5. Click Edit Parameters, define the method name, and specify the required method arguments by specifying the variable name and the corresponding field values.

  6. Click Save.
  7. Enter the description of the Custom Function.
  8. Enter the Deluge code, for more information, refer to Zoho - Deluge Scripting Language
    1. For Syntax auto-suggestion, enable Syntax Builder.
    2. For Connections, refer to Connections.
  9. Click Save.
    Idea
    Click Save and Execute to test and run the script immediately.
Info
Map the created custom function to a workflow to automatically run the code whenever a trigger event defined in the workflow occurs.

Map a Custom Function to Workflow

To Map a Custom Function to a Workflow:
  1. From your home page, go to Settings > Select a Service > Workflows > Add Workflow.
  2. Provide all the required details, Learn more to configure Workflow.
  3. Under Actions, click Custom Functions and click the (+) add icon to add a new custom function to the workflow or you can select the existing custom function which are created for the form.

  4. Click Add.
    A workflow is created and based on the trigger events the custom function executes, performing the specified actions as defined in your code.

Use Cases

Automatic travel expense update using custom functions

Consider a scenario of calculating an employee's travel expenses. All of the travel expenses gets automatically calculated using the below custom function in the travel expense form. Thus, the respective employee's self-service form will get the updated travel expense details. To achieve this, a custom field has to be created in the employee self-service form.
  1. From your home page, go to Settings > Select a Service (Travel) > Automation > Actions > Custom Functions.
  2. Select respective Form (Travel Expense) and click  Add Custom Function.
  3. Provide a Custom Function Name and required parameter details
  4. Provide the script as given below.
  5. Click Save  to save the Custom Function.
    Idea
    Click Save and Execute to test and run the script immediately.
Quote
  1. travelExpenseMap = zoho.people.getRecordById("travelexpenses",travel_id);
  2. tabularList = travelExpenseMap.get("tabularSections").get("Expense");
  3. totalExp = 0;
  4. for each str in tabularList
  5. {
  6. totalExp = totalExp + str.get("Ticket").toDecimal() + str.get("Lodging").toDecimal() + str.get("LocalConveyance").toDecimal() + str.get("Boarding").toDecimal() + str.get("Others").toDecimal() + str.get("Incidentals").toDecimal() +str.get("Phone").toDecimal();
  7. }
  8. updateemp = Map();
  9. updateemp.put("recordid",erecno);
  10. updateemp.put("Total_Expense",totalExp);
  11. updaterecord = zoho.people.update("employee",updateemp);
  12. info updaterecord;

Automatically change the employee status from active to resigned during an employee's date of exit using Custom Functions

An employee is resigning his job and you want to change the status to 'Resigned' in the employee form during the date of exit. You can do this action using the below script in our custom function. By adding exit details for an employee, a workflow will be triggered where the mapped custom function will get executed. Upon successful execution, the selected employee's employee status value will be changed to 'Resigned'. Thus, the employee cannot log in to the organization account anymore.
  1. From your home page, go to Settings > Select a Service > Automation > Actions > Custom Functions.
  2. Select respective Form and click  Add Custom Function.
  3. Provide a Custom Function Name and required parameter details
  4. Provide the script as given below.
  5. Click Save  to save the Custom Function
    Idea
    Click Save and Execute to test and run the script immediately.
Quote
  1. getrecord = zoho.people.getRecordById("employee",erecno);
  2. params = Map();
  3. params.put("scope","creatorapi");
  4. params.put("Employee_ID",empid);
  5. params.put("First_Name",fname);
  6. params.put("Last_Name",lname);
  7. params.put("Email_ID",emailid);
  8. pushrecord = invokeurl
  9. [
  10.     type: POST
  11.     parameters: params
  12.     connection : "cf"
  13. ];
  14. info pushrecord;

Automatic check out in Attendance module

Let us consider a scenario, where an employee forgets to do check out on the system at the end of the day. It is possible to use Custom Functions to do an Auto-check out on the system. This helps in tracking the exact working hours of an employee.

Use the following parameters for both the methods mentioned below.



Method 1: When the check out is not done, Custom Functions can be used to update the respective shift's end time as the check out time on the system.
Steps:
  1. From your home page, go to Settings > Select a Service > Automation > Actions > Custom Functions.
  2. Select respective Form and click  Add Custom Function.
  3. Provide a Custom Function Name and required parameter details
  4. Provide the script as given below.
  5. Click Save to save the Custom Function
    Idea
    Click Save and Execute to test and run the script immediately.
Quote
  1. getUA = Collection();
  2. getUA.insert("erecno":erecno);
  3. get_Rec = invokeurl
  4. [
  5. url :"https://people.zoho.com/people/api/attendance/getUserAvailability"
  6. type :POST
  7. parameters:getUA.toMap()
  8. connection : "peoplecf"
  9. ];
  10. isUserAvailable = get_Rec.get("isUserAvailable");
  11. if(isUserAvailable == true)
  12. {
  13. getdata = zoho.people.getRecordByID("P_AttendanceForm",recordid.toLong());
  14. expcheckout = getdata.get("ExpectedToTime");
  15. addrecord = Map();
  16. addrecord.put("empId",empid);
  17. addrecord.put("checkOut",expcheckout);
  18. updaterecord = invokeurl
  19. [
  20.     url: "https://people.zoho.com/people/api/attendance"
  21.     type: POST
  22.     parameters: addrecord
  23.     connection : "peoplecf"
  24. ];
  25. info updaterecord;
  26. }
Method 2:  When the check out is not done,"08" hours from check-in time can be updated as check out time on the system using Custom Functions.
  1. From your home page, navigate to Settings > Select a Service > Automation > Actions > Custom Functions.
  2. Select respective Form and click  Add Custom Function.
  3. Provide a Custom Function Name and required parameter details
  4. Provide the script as given below.
  5. Click Save to save the Custom Function.
    Idea
    Click Save and Execute to test and run the script immediately.
Quote
  1. getUA = Collection();
  2. getUA.insert("erecno":erecno);
  3. get_Rec = invokeurl
  4. [
  5. url :"https://people.zoho.com/people/api/attendance/getUserAvailability"
  6. type :POST
  7. parameters:getUA.toMap()
  8. connection : "peoplecf"
  9. ];
  10. isUserAvailable = get_Rec.get("isUserAvailable");
  11. if(isUserAvailable == true)
  12. {
  13. getdata = zoho.people.getRecordByID("P_AttendanceForm",recordid.toLong());
  14. checkin = getdata.get("FromTime").toTime();
  15. addedhrs= checkin.addHour(8);
  16. addrecord = Map();
  17. addrecord.put("empId",empid);
  18. addrecord.put("checkOut",addedhrs);
  19. updaterecord = invokeurl
  20. [
  21.     url: "https://people.zoho.com/people/api/attendance"
  22.     type: POST
  23.     parameters: addrecord
  24.     connection : "peoplecf"
  25. ];
  26. info updaterecord;
  27. }
Info
Automatic check-out custom functions can be used only when all employees in the organization belong to the same time zone.

Automatic conversion of any currency to USD

Irrespective of the amount in the travel claim form, the currency will be converted to USD based on the exchange rate of the day on which the claim is raised.
  1. From your home page, navigate to Settings > Select a Service (Travel) > Automation > Actions > Custom Functions.
  2. Select respective Form (Travel Claim Form) and click  Add Custom Function
  3. Provide a Custom Function Name and required parameter details.
    Info
    Parameters:
    recordId = ZohoID(Travel Claim) 
  4. Provide the script as given below.
  5. Click Save to save the Custom Function.
    Idea
    Click Save and Execute to test and run the script immediately.
Quote
  1. getValues = zoho.people.getRecordById("Travel_Claim",recordId);
  2. tabularsec = getValues.get("tabularSections").get("Cost Details");
  3. result = 0;
  4. for each tabularsecvalues in tabularsec.toList()
  5. {
  6. cost = tabularsecvalues.get("");
  7. format = tabularsecvalues.get("");
  8. if(format != "USD" && cost > 0.00 && format != "")
  9. {
  10. currencyvalues = getUrl("https://data.fixer.io/api/latest?access_key=YOUR_ACCESS_KEY&base=USD");
  11. formatvalues = currencyvalues.get("rates").get(format);
  12. totalval = cost.toDecimal() * formatvalues.toDecimal();
  13. total = totalval.round(2);
  14. result = total + result;
  15. }
  16. }
  17. addrecmap = Map();
  18. addrecmap.put("recordid",recordId);
  19. addrecmap.put("total",result.toString());
  20. addtotal = zoho.people.update("Travel_Claim",addrecmap);
  21. info addtotal;
Idea
Navigate to Settings > Developer Space > Zoho People API tab to know more about form and field link names.

Adding leave balance

If leave balance has to be given to an employee, the below code can be used. leave type ID of a particular leave type can be obtained from this API and can be replaced in the code.
  1. From your home page, navigate to Settings > Select a Service (Leave) > Automation > Actions > Custom Functions.
  2. Select respective Form (Leave) and click  Add Custom Function
  3. Provide a Custom Function Name and required parameter details.
    Info
    Parameters:
    erecno = ID (Employee ID)
    count = count (Leave credit)
  4. Provide the script as given below.
  5. Click Save to save the Custom Function.
    Idea
    Click Save and Execute to test and run the script immediately.
Quote
  1. param = Collection();
  2. leavetypeid = "494174000000515325";
  3. details = "{" + erecno + ":{" + leavetypeid + ":{'date':" + today.toString("dd-MMM-yyyy") + ",'count':" + count + "}}}";
  4. param.insert("balanceData":details);
  5. getRecord = invokeurl
  6. [
  7.     url :"https://people.zoho.com/people/api/leave/addBalance"
  8.     type :POST
  9.     parameters:param.toMap()
  10.     connection:"people_cf"
  11. ];
  12. info getRecord;

Send email if total hours for a week is less than 45 hours for an employee

By making use of the below script, if total hours of attendance is less than 45 hours for an employee, then an email can be sent.
  1. From your home page, navigate to Settings > Select a Service (Leave) > Automation > Actions > Custom Functions.
  2. Select respective Form (Leave) and click  Add Custom Function
  3. Provide a Custom Function Name and required parameter details.
    Info
    Parameters:
    erecno = ID (Employee ID)
    count = count (Leave credit)
  4. Provide the script as given below.
  5. Click Save to save the Custom Function.
    Idea
    Click Save and Execute to test and run the script immediately.
Quote
  1. start_date = today.toDate().subDay(7);
  2. end_date = today.toDate().subDay(1);
  3. getrec_Col = Collection();
  4. getrec_Col.insert("startDate":Start_Date);
  5. getrec_Col.insert("endDate":End_Date);
  6. getrec_Col.insert("dateFormat":"dd-MMM-yyyy");
  7. get_rec = invokeurl
  8. [
  9. url :"https://people.zoho.com/people/api/attendance/getSummaryReport"
  10. type :POST
  11. parameters:getrec_Col.toMap()
  12. connection : "cf"
  13. ];
  14. summary_Reports = get_rec.get("summaryReport");
  15. for each  summary in summary_Reports
  16. {
  17. emailId = summary.get("emailId");
  18. totalWorkedDays = summary.get("totalHours");
  19. totalWorkedDays = totalWorkedDays.getPrefix(":").toNumber();
  20. if(totalWorkedDays < 45)
  21. {
  22.     sendmail
  23.     [
  24.         from : zoho.adminuserid
  25.         to : emailId
  26.         subject: "Total Hours"
  27.         message : "<div>Hi,<br></div><div><br></div><div>You have not completed 45 hours for the previous week.<br></div><div><br></div><div>Thanks,<br></div><div>Admin Team</div>"
  28.     ]
  29. }
  30. }

IdeaNavigate to Settings > Developer Space > Zoho People API tab to know more about form and field link names.
Info
The above scripts can also be edited and used to serve other similar scenarios.
Info
All APIs used in Custom Functions have threshhold limits. Refer the API guide for the limits under each module and customize the code accordingly.

    Access your files securely from anywhere

      Zoho CRM Training Programs

      Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

      Zoho CRM Training
        Redefine the way you work
        with Zoho Workplace

          Zoho DataPrep Personalized Demo

          If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

          Zoho CRM Training

            Create, share, and deliver

            beautiful slides from anywhere.

            Get Started Now


              Zoho Sign now offers specialized one-on-one training for both administrators and developers.

              BOOK A SESSION





                          Quick Links Workflow Automation Data Collection
                          Web Forms Enterprise Begin Data Collection
                          Interactive Forms Workplace Data Collection App
                          CRM Forms Customer Service Accessible Forms
                          Digital Forms Marketing Forms for Small Business
                          HTML Forms Education Forms for Enterprise
                          Contact Forms E-commerce Forms for any business
                          Lead Generation Forms Healthcare Forms for Startups
                          Wordpress Forms Customer onboarding Order Forms for Small Business
                          No Code Forms Construction RSVP tool for holidays
                          Free Forms Travel
                          Prefill Forms Non-Profit

                          Intake Forms Legal
                          Mobile App
                          Form Designer HR
                          Mobile Forms
                          Card Forms Food Offline Forms
                          Assign Forms Photography
                          Mobile Forms Features
                          Translate Forms Real Estate Kiosk in Mobile Forms
                          Electronic Forms

                          Notification Emails for Forms Alternatives Security & Compliance
                          Holiday Forms Google Forms alternative  GDPR
                          Form to PDF Jotform alternative HIPAA Forms
                          Email Forms
                          Encrypted Forms
                          Embeddable Forms
                          Secure Forms
                          Drag and Drop form builder
                          WCAG


                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                Manage your brands on social media

                                                  Zoho Desk Resources

                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                    Zoho Marketing Automation

                                                      Zoho Sheet Resources

                                                       

                                                          Zoho Forms Resources


                                                            Secure your business
                                                            communication with Zoho Mail


                                                            Mail on the move with
                                                            Zoho Mail mobile application

                                                              Stay on top of your schedule
                                                              at all times


                                                              Carry your calendar with you
                                                              Anytime, anywhere




                                                                    Zoho Sign Resources

                                                                      Sign, Paperless!

                                                                      Sign and send business documents on the go!

                                                                      Get Started Now




                                                                              Zoho TeamInbox Resources



                                                                                      Zoho DataPrep Resources



                                                                                        Zoho DataPrep Demo

                                                                                        Get a personalized demo or POC

                                                                                        REGISTER NOW


                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now









                                                                                                              • Related Articles

                                                                                                              • Zoho People 5.0 - What has changed?

                                                                                                                Changes in Home tab and Self Service Zoho People 4.0 Zoho People 5.0 Landing page is Home > Dashboard Self Service page: New Landing page is Home > My Space > Overview (Replacement for Self service in Zoho People 4.0 with additional features). ...
                                                                                                              • Zoho People 5.0 Administrator Guide

                                                                                                                What is Zoho People 5.0? Zoho People is a comprehensive cloud-based HR software that aims to streamline HR processes, enhance employee engagement, and improve workforce productivity. With this refreshing new version, Zoho People further aims to ...
                                                                                                              • Settings in Zoho People 5.0

                                                                                                                What can you do in settings? Settings lets you setup Zoho People to handle your organization's HR Processes. It Includes: Setting up your organization's information in Zoho People. This includes basic details such as name, type of organization, ...
                                                                                                              • Operations in Zoho People 5.0

                                                                                                                What can you do in Operations? Manage your employees, organization, and perform day-to-day HR processes in operations. For example, while setting up policies is performed in settings, viewing relevant data, modifying, or updating that data happens in ...
                                                                                                              • Zoho People Home Tab

                                                                                                                What is Home tab in Zoho People? The Home tab is the landing page for Zoho People. The first tab that is presented is the Overview page with a quick shortcut to Check-in, see hours clocked, your reportees, and your favorites list. The main attraction ...
                                                                                                                Wherever you are is as good as
                                                                                                                your workplace

                                                                                                                  Resources

                                                                                                                  Videos

                                                                                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                  eBooks

                                                                                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                  Webinars

                                                                                                                  Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                  CRM Tips

                                                                                                                  Make the most of Zoho CRM with these useful tips.



                                                                                                                    Zoho Show Resources