## Documentation Index Access the complete documentation index at: https://www.zoho.com/ae/books/help/llms.txt Use this file to discover all available documentation pages before proceeding. # Automation Automation allows you to create rules that trigger actions automatically. You can set up workflow rules, define conditions for execution, and associate actions such as email alerts, in-app notifications, field updates, webhooks and functions. Additionally, you can create schedules for workflow rules and view logs of executed workflows. * * * ## Workflow Rules You can automate tasks such as sending emails, updating fields, and triggering webhooks or functions by creating workflow rules in Zoho Books. The workflow rule executes automatically once the conditions are met. **Scenario:** John wants to automatically send a thank-you email with discount coupons to customers after they make a purchase. For this, he sets up a workflow rule in Zoho Books so that whenever a customer completes their payment, the rule triggers the email alert, and an email is sent automatically, saving time and effort for John. * * * ## Create a New Workflow Rule To create a new workflow rule: * Go to **Settings**. * Select **Workflow Rules** under _Automation_. * Click **\+ New Workflow Rule** in the top right corner. * In the _New Workflow Rule_ pop-up, fill in the following fields: * **Workflow Rule Name:** Enter a name for the workflow rule. * **Description:** Add a description if necessary. * **Module:** Select the module for the workflow rule from the drop-down menu. **Note:** You can create workflow rules for the following modules: * Sales * Purchases * Time Tracking * Contacts * Bank Transactions * Accountant * Tasks * Items * Inventory Adjustments * Payment Batches * Vendor Batch Payments * Click **Next**. * Under _WORKFLOW RULE EXECUTION CONDITION_, fill in the following fields: * **Workflow Type:** Choose either **Event Based** or **Date Based**. * **Action Type:** Select the action type that triggers the workflow. * **Execute the workflow when:** Choose the actions that trigger the workflow (Edit, Edited or Created). * **Execute when the record is:** Select either **Edited for the first time** or **Edited each time**. **Note:** **Execute the workflow when** and **Execute when the record is** fields will only appear when the **Action Type** is set to **Edited** or **Edited or Created**. * Click **Next**. * Click **\+ New Criteria** to create a new criteria for the workflow rule: * In the right sidebar, click **Yes** to add criteria or **No** to skip. * Select a field, the comparator, and enter the necessary value. * Click **\+ Add Criterion** or **+** to create additional criteria if necessary. * If you add multiple criteria, select either **AND** or **OR** from the dropdown based on how you want the criteria to work. You can also edit the criteria pattern by manually entering the criteria in the _CRITERIA PATTERN_ field. * Once you’ve added the necessary criteria, click **Done**. * Add actions by selecting from the options below: * **\+ Immediate Actions:** Triggers actions immediately when the criteria are met. * In the right sidebar, select the type of workflow action you want to associate with the workflow rule from the _Type_ dropdown. Next, from the _Name_ dropdown, choose the workflow action you created and configured, or click **\+ New %Workflow Action%** from the dropdown to add a new workflow action. * Click **\+ Add New Action** to add more actions if necessary. * Click **Associate** to finish associating actions with the criteria. * **\+ Time Based Actions:** Triggers actions based on the scheduled time. * In the right sidebar, In the _EXECUTION TIME_ field, set the time for when the action will be executed. * Select the type of workflow action you want to associate with the workflow rule from the _Type_ dropdown. Then, from the _Name_ dropdown, choose the workflow action you created and configured, or click **\+ New %Workflow Action%** from the dropdown to add a new workflow action. * Click **\+ Add New Action** to add more actions if necessary. * Click **Associate** to finish associating actions with the criteria. * Click **Save** to finalize and save the workflow rule. Now, once you’ve created the workflow rule, whenever an action occurs that matches the trigger you set in the workflow rule, the rule will execute, and the specified action will take place. **Note:** You can create up to 10 criteria for one workflow, and within each criterion, you can add up to 10 criteria. * * * ## Other Actions in Workflow Rules ### Change the Order of Workflow Rules If you want to view specific workflow rules at the top of the List View page or in a specific order, you can reorder them. Here’s how: * Go to **Settings**. * Select **Workflow Rules** under _Automation_. * Select the module where you want to change the order of workflow rules by clicking the Module dropdown. * Click **Change Order** in the right corner. * Now, pick and reorder the rules based on your preference. * After making the necessary reorder, click **Save Reorder**. ### Edit a Workflow Rule * Go to **Settings**. * Select **Workflow Rules** under _Automation_. * Hover over and select the workflow rule you want to edit, and click **Edit**. * Make your changes, and click **Save**. ### Clone a Workflow Rule If you need a new workflow rule with the same details present in an existing workflow rule, you can clone the existing rule. Here’s how: * Go to **Settings**. * Select **Workflow Rules** under _Automation_. * Hover over the workflow rule you want to clone, click the dropdown to the right, and select **Clone**. * In the _New Workflow Rule_ page, review the cloned details. * Verify the _WORKFLOW RULE EXECUTION CONDITIONS_, and click **Update**. * Click **Save**. ### Mark a Workflow Rule As Inactive If you won’t be using a workflow rule for a while but want to keep it for future use, you can mark it as inactive instead of deleting it. To mark it as inactive: * Go to **Settings**. * Select **Workflow Rules** under _Automation_. * Hover over the workflow rule you want to mark as inactive, click the dropdown to the right, and select **Mark as Inactive**. ### Configure Notification Preferences for Workflow Rules **Insights:** * You can trigger a workflow alert up to 500 times a day. * Admins will also receive in-app notifications when any workflow action crosses the specified threshold. You can set daily limits for workflow alert triggers and add email recipients to get notified when the daily threshold is reached. You can also configure how you receive failure log notifications when a workflow rule fails. To configure: * Go to **Settings**. * Select **Workflow Rules** under _Automation_. * Click **Configure Notification Preferences** in the top right corner. * In the _Configure Notification Preferences_ popup, fill in the following fields: * **Usage Limit Notifications:** Choose a threshold for sending notifications for workflow actions like email alerts, webhooks, and functions. * **Failure Log Notifications:** Select the frequency and time for notifications, and specify the email recipients who will receive the failure log updates if needed. * Click **Save**. ### Delete a Workflow Rule * Go to **Settings**. * Select **Workflow Rules** under _Automation_. * Hover over the workflow rule you want to delete, click the dropdown to the right, and select **Delete Workflow Rule**. * In the popup that follows, click **Yes** to confirm. * * * ## Workflow Actions ### Email Alerts The following steps will explain how to set up an email alert for any module in Zoho Books. **Creating a new Email Alert:** To set up an email alert, navigate to ![ ](/books/help/images/gear-icon.png) **\> Automation > Email Alerts** and click on **\+ New Email Alert**. ![New Email Alert](/books/help/images/settings/Automation-NewEmailAlert.png) **Field** **Description** **Name** Give a unique name for the email alert. **Module** Select the module for which you wish to create an email alert. **Email Template** You can pick a template from the drop down or click on **\+ Add New Email Template** if you wish to create a new one. ![email temp drop](/books/help/images/settings/Automation-EmailTemplateDropdown.png) **Email Recipients** Pick contacts from the drop down, to whom you wish to send the email alerts. **Additional Recipients** If you wish to send out email alerts to more people, enter their email addresses separated by a comma. Please note that you can add a maximum of 10 additional recipients. Click on **Save** to create a new email alert. You can now select one of the many email alerts created, from the drop down, to notify you when a workflow is triggered. #### Other Actions in Email Alerts **Delete an email alert:** To delete an email alert, hover the cursor next to an email alert on the list and click on the **Delete** icon. ![Delete email alert](/books/help/images/settings/Automation-DeleteEmailalert.png) **Filter email alerts:** To filter the email alerts list, follow these steps: * Navigate to ![ ](/books/help/images/gear-icon.png) **\> Automation > Email Alerts**. * Under **Module**, select a module from the drop down for which the email alert has been created. Based on your selection, the corresponding email alerts will be displayed as a list. ![Filter Email Alert](/books/help/images/settings/Automation-FilterEmailAlert.png) **Notes:** * You can create a maximum of 5 email alerts for each workflow rule. * A maximum of 500 email alerts can be triggered per day. ##### In-app Notifications Zoho Books lets you create in-app notifications to notify your users of an event or a significant activity that has taken place in your organisation. You will be able to set this for all the modules and also choose when to trigger the notification. **Scenario:** Let’s say the sales team has made a sale worth 100000 in your organisation. All the admins and users of the organisation may not be aware of the sale. Triggering an in-app notification for invoices whose total is above the organisation’s average sale value would have notified all the users of the organisation. Similarly, you will be able to set up a workflow rule to trigger in-app notifications for your organisation. Here’s how: * Go to **Settings** on the top right corner of the page. * Select **Workflow Actions** under _Automation_. * In the _Workflow Actions_ pane, select **In-app Notifications**. * Click **\+ New In-app Notification** in the top right corner. * On the _New In-app Notification_ page: * Create a [new workflow rule](/ae/books/help/settings/automation.html#new-workflow-rule) by entering a **Name** and selecting the **Module**. * Choose [when](/ae/books/help/settings/automation.html#workflow-type) you want to trigger the notification – **Event Based** or **Date Based.** * Set up [**filters** and **criteria**](/ae/books/help/settings/automation.html#filter-the-triggers) for the workflow and click **Next**. ![Workflow](/books/help/images/settings/notification-workflow.png) * Select the **Action Type** as **In-app Notifications**. * Create a new notification by clicking **\+ New In-app Notification** under **Sale**. ![New Notification](/books/help/images/settings/notification-new.png) * Enable the option to **add time based actions** and choose when you would like to execute the action. * Set the criteria and click **Save**. ![Set Criteria](/books/help/images/settings/notification-actions.png) The next time the action occurs, selected recipients will be notified in the **Bell** icon. Click it to view the details. ![Notification](/books/help/images/settings/notification-icon.png) * * * ### Field Updates The option of **Field Updates** allows you to automatically make changes to a field of a particular module for which the workflow has been triggered. For example, you can choose to automatically extend the expiry date to 30th June 2015 of a quote if the total amount is greater than or equal to $500. In this case, the **Expiry Date** field is changed to the above date if the **Total** field is “>=“500. To set up a field update: * Go to **Settings** on the top right corner of the page. * Select **Workflow Actions** under _Automation_. * In the _Workflow Actions_ pane, select **Field Updates**. * Click **\+ New Field Update** in the top right corner. * On the _New Field Update_ page, enter the following details: ![New Field Update](/books/help/images/settings/Automation-NewFieldUpdate.png) **Field** **Description** **Name** Give a unique name for the field update. **Module** Select a module for which you wish to create a field update. **Update** Select the field in which you wish to make changes upon triggering a workflow from the drop down. \-Reference # \-Expiry Date \-Sales Person \-Notes \-Terms & Conditions \-Adjustment Description Enter the value of the field in the corresponding box. If you wish to update the field with an empty value, check the box **Update with empty value?**. ![Update Empty Value](/books/help/images/settings/Automation-FieldUpdateValue.png) * Click on **Save** to create a new field update. You can now select one of the many field updates created to implement changes when the workflow is triggered. #### Other Actions in Field Updates ##### Delete a Field Update To delete a field update: * Go to **Settings** on the top right corner of the page. * Select **Workflow Actions** under _Automation_. * In the _Workflow Actions_ pane, select **Field Updates**. * Hover the cursor over the field update that you want to delete and click the **Delete** icon. ![Delete Field Update](/books/help/images/settings/Automation-FieldUpdateDelete.png) ##### Filter Field Updates To filter the field updates: * Go to **Settings** on the top right corner of the page. * Select **Workflow Actions** under _Automation_. * In the _Workflow Actions_ pane, select **Field Updates**. * Under **Module**, select a module from the dropdown for which the field update has been created. Based on your selection, the corresponding field updates will be displayed as a list. ![Filter Field Update](/books/help/images/settings/Automation-FieldUpdateFilter.png) **Note:** You can create a maximum of 3 field updates for each workflow rule. * * * ### Webhooks Webhooks facilitate communication with third-party applications by sending instant web notifications every time an event occurs in Zoho Books. With Webhooks, you can configure HTTP & HTTPS URLs and associate them with workflow rules to automate the notification process. Read our help document on [webhook examples](/ae/books/help/settings/using-webhook.html) to know more about when and how you can use webhooks. For general information about webhooks, visit [webhooks.org](http://webhooks.org). #### Create a Webhook To set up a webhook: * Go to **Settings** on the top right corner of the page. * Select **Workflow Actions** under _Automation_. * In the _Workflow Actions_ pane, select **Webhooks**. * Click **\+ New Webhook** in the top right corner. ![Click + New Webhook](/books/help/images/settings/webhooks/plus-new-webhook.png) * On the _New Webhook_ page, enter the following details: * Enter a name for the webhook in the **Name** field. * Select the module for which you want to create the webhook from the dropdown next to the **Module** field. * Add a description about the webhook in the **Description** field, if required. ![New Webhook page](/books/help/images/settings/webhooks/new-webhook-page.png) * In the **URL & Parameters** field, select the HTTP method and enter the URL of the third-party application. The HTTP methods available in Zoho Books are listed below: * **Post**: Requests that the data sent must be considered as new * **Put**: Requests that the data sent should be considered as a modified version of the one already present * **Delete**: Requests that the data must be deleted. **Note:**If you want to specify a port number in the **URL and Parameters** field, note that Zoho Books only supports port numbers **80** and **443**. You can also add additional query parameters by clicking **Add Parameters** and entering the required values in the **Key** and **Value** fields. You can add custom parameters like Auth Token, Security Token, API Key, etc. ![URL and Parameters ](/books/help/images/settings/webhooks/url-and-parameters.png) * Check the **I want to secure this webhook** option if you want to secure your webhook. Enter the secret key in the **Secret Token** field. This will help to verify whether the webhook was sent from Zoho Books. It should be alphanumeric and range between 12-50 characters. **Note**: You cannot edit or view the secret token later. ![Secret Token](/books/help/images/settings/webhooks/secret-token.png) **Note:** The secret token will be used to compute a hash value, so, you will have to ensure that the same token is available on your server to compute a similar hash value. * In the Headers section, you can include any additional information that you want to be included in the HTTP request. Click **\+ Add New Headers** if you want to add additional headers. ![Headers](/books/help/images/settings/webhooks/headers.png) * In the **Authorisation Type** section, choose how you want to authorise the webhook. * **Self-Authorisation**: Select this option to set up your webhook by providing the authorisation details manually. * **Connections**: Select this option to set up your webhook using a connection. Read our help document on Connections to learn [how to create connections](/ae/books/help/settings/connections.html). ![Authorization Type](/books/help/images/settings/webhooks/authorization-type.png) * In the **Body** section, choose how you want to send the data. You can choose from the following body parameters: * **Default Payload**: In the default payload format, all the parameters associated with the module will be sent to the request body in the application/json format content type. * **form-data**: Send data as text or files. If you select **File**, the custom fields for the attachment type created in the module for which you are creating this webhook will be listed in the dropdown. * **x-www-form-urlencoded**: In the x-www-urlencoded format, the data will be encoded and sent to the server. * **Raw**: In the raw format, you can choose the parameters sent to the request body. The content type will be application/json. ![Body](/books/help/images/settings/webhooks/body.png) * Click **Save and Execute** to check if the webhook works properly, or click **Save** if you want to execute it later. **Note**: When you set up webhooks, all your contacts’ details in your Zoho Books organisation (name, phone number, address, and email address) will be shared with the URL you want to notify. #### Webhook Examples To help you understand how webhooks work in Zoho Books, we’ve outlined a few [examples](/ae/books/help/settings/using-webhook.html). These will give you a clear idea of how webhooks can be applied to meet your business needs. #### Secure Your Webhooks Securing your webhooks can help verify that the webhooks were sent from Zoho Books. To do this, you have to set up your server so that it listens for webhooks from Zoho Books. When your server receives a webhook from Zoho Books, a hash value must be generated based on the payload and your secret token. Once done, check if it matches the hash value from Zoho Books and thereby validate the source of the webhook. This can add a layer of security by enabling your server to disregard third-party webhooks pretending to originate from Zoho Books. #### Validate Webhooks When your server receives the webhook, a hash value will have to be generated for the payload in the same way that Zoho Books generated it. This is necessary to produce the same hash value to validate the webhook. The following parameters (if available) are used to generate the hash value: * Query string parameters. * Default payload or customised raw JSON payload. * x-www-form-urlencoded payload (key-value pairs). Construct a string by sorting the payload’s key-value pairs in alphabetical order. The pairs must be sorted in alphabetical order with respect to their keys. **Note** * If your webhook contains **query string parameters**, ensure that those key-value pairs are sorted along with the payload’s key-value pairs. * There cannot be any spaces between the key-value pairs. Once you’ve sorted the key-value pairs and constructed the string, append the raw JSON to the end of the string. **Examples** 1\. **Default Payload** Query string parameters’ key-value pairs: ``` subscription\_id=90343, name=basic ``` Default payload/raw JSON: ``` {"created\_date":"2019-03-06","event\_id":"5675"} ``` The constructed string would be: ``` namebasicsubscription\_id90343{"created\_date":"2019-03-06","event\_id":"5675"} ``` 2\. **x-www-form-urlencoded** Query string parameters’ key-value pairs: ``` customer\_name=Brandon, status=active ``` x-www-form-urlencoded payload’s key-value pairs: ``` addon\_description=Monthly addon, quantity=1 ``` The constructed string would be: ``` addon\_descriptionMonthly addoncustomer\_nameBrandonquantity1statusactive ``` **Pro Tip** * If your payload is in the x-www-form-urlencoded format, the entire string must be decoded before generating the hash value. * If one of the key value pairs contains spaces, the spaces must also be included in the constructed string. The hash value can be computed by applying the HMAC-SHA256 algorithm on this string, along with the secret token that was used in Zoho Books. You can then validate the webhook by checking if the hash value computed from your side matches the one in the header (X-Zoho-Webhook-Signature) of the webhook from Zoho Books. You can verify your webhook signature using the following programming languages: **JavaScript:** ```sh const crypto = require('crypto'); function verifyWebhook(queryParams, bodyParams, signature, secretKey) { try { const constructedString = constructString(queryParams, bodyParams); const hmac = crypto.createHmac('sha256', secretKey); hmac.update(constructedString); const calculatedSignature = hmac.digest('base64'); return calculatedSignature === signature; } catch (error) { console.error(error); return false; } } function constructString(queryParams, bodyParams) { // Merge and sort keys const allParams = { ...queryParams, ...bodyParams }; const sortedKeys = Object.keys(allParams).sort(); let result = ''; for (const key of sortedKeys) { result += key + allParams[key]; } return result; } ``` **Java:** ```sh import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.util.Map; import java.util.TreeMap; import java.util.Base64; public class Hmacverify { public static boolean verifyWebhook(Map queryParams, Map bodyParams, String signature, String secretKey) { try { String constructedString = constructString(queryParams, bodyParams); Mac sha256HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256"); sha256HMAC.init(secretKeySpec); byte[] hash = sha256HMAC.doFinal(constructedString.getBytes()); String calculatedSignature = Base64.getEncoder().encodeToString(hash); return calculatedSignature.equals(signature); } catch (Exception e) { e.printStackTrace(); return false; } } private static String constructString(Map queryParams, Map bodyParams) { StringBuilder result = new StringBuilder(); TreeMap sortedParams = new TreeMap<>(queryParams); sortedParams.putAll(bodyParams); for (Map.Entry entry : sortedParams.entrySet()) { result.append(entry.getKey()).append(entry.getValue()); } return result.toString(); } } ``` **Python:** ```sh import hmac import hashlib import base64 def verifyWebhook(queryParams, bodyParams, signature, secretKey): constructedString = constructString(queryParams, bodyParams) calculatedSignature = base64.b64encode(hmac.new(secretKey.encode(), constructedString.encode(), hashlib.sha256).digest()).decode() return calculatedSignature == signature def constructString(queryParams, bodyParams): # Merge and sort query and body parameters allParams = {**queryParams, **bodyParams} sortedParams = sorted(allParams.items()) result = ''.join([key + value for key, value in sortedParams]) return result ``` # Example usage queryParams = {‘subscription\_id’: ‘90343’, ’name’: ‘basic’} bodyParams = {‘created\_date’: ‘2019-03-06’, ’event\_id’: ‘5675’} signature = ‘provided-signature’ secretKey = ‘your-secret-key’ verifyWebhook(queryParams, bodyParams, signature, secretKey) #### Configuring SMS Gateways  You can set up webhooks to send and receive message alerts through SMS gateways. All you have to do is configure the SMS gateways using the URL and follow the steps provided below.  ##### Bulk SMS Bulk SMS is a popular SMS Gateway and is compatible with over 800 mobile network providers, worldwide. **URL: https://bulksms.vsms.net/eapi/submission/send\_sms/2/2.0?username=`%username%`&password=`%password%`&msisdn=${CONTACT.CONTACT\_MOBILE\_PHONE}&message=%message\_content%** To configure the URL for Bulk SMS: * Click the **Gear** icon on the top right and select Automation. * Navigate to the\*\* Webhooks\*\* tab and click **\+ New Webhook**. * Copy the above URL into the **URL to notify** field. * Replace the **%username%** and **%password%** placeholders in the URL with the username and password of your Bulk SMS account. * Type your message at the end of the URL, i.e. after “**message=**".  * Replace all the blank spaces in your message content by **%20** and all the commas by **%2C**. ![Configure Bulk SMS](/books/help/images/settings/bulk-sms.png) **Note:** If there are other punctuations in your message content, you can check how to replace them with modifiers from [this](https://meyerweb.com/eric/tools/dencoder/) website. However, ensure that you do not replace punctuations that are essential to the message’s syntax. After formatting your message with %20 for blank spaces and %2C for commas, it should look like this: > **URL: https://bulksms.vsms.net/eapi/submission/send\_sms/2/2.0?username=`%username%`&password=`%password%`&msisdn=${CONTACT.CONTACT\_MOBILE\_PHONE}&message=Hello%20${CONTACT.CONTACT\_NAME}.Thank%20you%20for%20the%20purchase%20of%20${INVOICE.INVOICE\_TOTAL}** **Similarly, other SMS gateways can be configured, with only the URL being different.**  ##### SMS-Magic SMS gateways such as SMS-Magic requires you to enter additional entity parameters to configure the webhook.  To configure SMS-Magic: * Enter the URL **https://sms-magic.in/smapi/post** in the **URL** to notify field. * Click **+Add Entity Paramter**. * Enter the following text in the parameter field: ![Configure SMS Magic](/books/help/images/settings/sms-magic.png)   ``` **User_ID** **%Sender_ID** **%Account_ID** **%hashkey%** ``` Replace the placeholders in the URL with the User ID, Sender ID and Account ID of your SMS-Magic account. The hashkey refers to a standard hashed md5 value of a string that is a concatenation of your User ID, Password, Account ID and Sender ID. **Note:** To generate the hashed md5 value, you can visit [this](https://www.md5hashgenerator.com/) site.  ##### Text Local Text Local requires an entity parameter and a custom parameter to function. To configure Text Local: ![Configure Text Local](/books/help/images/settings/text-local.png) * Enter the URL **http://api.textlocal.in/send/** in the **URL to notify** field.   * Click **\+ Add Custom Parameter**. * Add the **sender** and **apikey** parameter and replace the placeholders in the URL with the relevant information from Text Local. * Click **\+ Add Entity Parameter**. * Give a name for the parameter and select the required conditions from the dropdown menu. Example: numbers = ${CONTACT.CONTACT\_MOBILE\_PHONE}  * Select the **Add User Defined Parameters** box and enter the message to be sent along with all the necessary place holders.  * Click **Save**. #### Other Actions in Webhooks ##### Delete Webhooks To delete a webhook: * Go to **Settings** on the top right corner of the page. * Select **Workflow Actions** under _Automation_. * In the _Workflow Actions_ pane, select **Webhooks**. * Hover over the webhook that you want to delete and click the **Delete** icon. ![Click the Delete icon](/books/help/images/settings/webhooks/delete-webhook.png) * In the pop up that appears, click **Yes**. The webhook will be deleted. If you’ve used in the webhook in a workflow rule, ensure that you update the workflow rule as the workflow rule might not get triggered. ##### Filter Webhooks To filer the webhooks list, follow these steps: * Go to **Settings** on the top right corner of the page. * Select **Workflow Actions** under _Automation_. * In the _Workflow Actions_ pane, select **Webhooks**. * Under Module, select a module from the drop down for which the webhook been created. Based on your selection, the corresponding webhook will be displayed as a list. ![Filter Webhook](/books/help/images/settings/Automation-FilterWebhook.png) **Note** * You can create only 1 webhook for each workflow rule. * A maximum of 500 webhooks can be triggered per day. * * * ### Functions Functions in Zoho Books allows you to write small pieces of code to automate your business processes. Be it providing a special discount on your customers’ invoice, or adding a late fee when an invoice becomes overdue, all you have to do is write a piece of code using Deluge script and link it to a workflow rule and automation of the process will be taken care of. #### What is Deluge? **Deluge(Data Enriched Language for the Universal Grid Environment)** is an online scripting language integrated with Zoho Creator. It enables users to add logic to the application, incrementally, making it more powerful and robust. To know about Deluge, refer the [Deluge Reference Guide](https://www.zoho.com/deluge/help/). If you wish to learn Deluge by writing code samples, click [here](https://creator.zoho.com/learndeluge/#Welcome!). #### Creating and Executing a Function To setup a function, * Go to **Settings** on the top right corner of the page. * Select **Workflow Actions** under _Automation_. * In the _Workflow Actions_ pane, select **Functions**. * Click **\+ New Function** in the top right corner. ![New Function button](/books/help/images/settings/custom-function-button.png) * On the _New Function_ page: * Enter a **Name** for your function and provide a small **Description**. * Choose the **Module** for which you want to create the function. * Choose the **Programming Language** in which you want to write the function’s code. * If you chose _Deluge_ as the programming language, click **Proceed** and type in or drag the parameters into the **Deluge editor**. * If you chose a programming language other than Deluge, you need to enter the function’s code using the [Zoho Finance CLI.](/ae/books/help/settings/custom-functions-using-zoho-finance-cli.html) You can use [context methods](/ae/books/help/settings/custom-functions-context-methods.html) to interact with platform features such as logging, caching, queues, file storage, scheduled execution, and third-party connectors. ![New predefined connection](/books/help/images/settings/custom-function-form.png) * Once done, click **Save**. Now, the next step is to create a workflow rule using the newly created function. * Head back to the _Automation_ pane and select **Workflow Rules**. * Create a new workflow and set the triggers. * Now, under the **Actions** tab, choose **Functions** and select your newly created function. * Click **Save.** Now, whenever the criteria is met, the workflow rule will be triggered, which in turn will trigger the function. ##### Default fields As of now, functions support Users, Organisation, Quotes, Invoices, Sales Orders, Purchase Orders, Customers, Recurring Invoices, Expenses, Bills, Recurring Bills, and Items modules. These modules will have the following fields from which you can get the necessary parameters for your function. ###### User The user field supports the following parameters: Key Fields Description name Name of the user zuid ZUID of the user ##### Organization The organisation map supports the following fields: Key Fields Description organisation\_id Your organisation ID name Organisation name time\_zone Time zone of your organisation language\_code Organisation’s language date\_format Your organisation’s date format currency\_id Currency ID currency\_code Currency code currency\_symbol Currency symbol address Organisation address phone Organisation’s contact number fax Fax number website Organisation URL email Email address portal\_name Portal name of your organisation **Sample map:** ``` { "time_zone": "Asia/Calcutta", "language_code": "en", "currency_id": "7605000000000099", "phone": "99999999999", "fax": "check", "website": "", "email": "charles@zylker.com", "address": { "zip": "624001", "country": "India", "city": "New Delhi", "street_address2": "Block 15", "street_address1": "6/35 Garden Lane,", "state": "Delhi" }, "organisation_id": "12345678", "name": "Zlyker Industries", "date_format": "dd MMM yyyy", "currency_symbol": "Rs.", "portal_name": "zylkerindustry", "currency_code": "INR" } ``` ##### Quote The quote map supports the following fields: Key Fields Description quote\_id Quote ID quote\_number Your quote number date Quote date reference\_number Reference number of your quote status Status of your quote customer\_id ID of the customer who is assigned to the quote customer\_name Your customer’s name currency\_id Currency ID currency\_code Currency code currency\_symbol Currency symbol exchange\_rate Exchange rate involved in the quote expiry\_date Expiry date of the quote discount\_amount Discount amount discount Discount shipping\_charge Shipping charge entered in the quote adjustment Adjustments sub\_total Sub total of the quote total Quote total tax\_total Total tax amount in the quote billing\_address Billing address of the customer shipping\_address Shipping address of the customer notes Notes terms Terms and conditions custom\_fields Quote custom fields salesperson\_id ID of the salesperson salesperson\_name Name of the salesperson **Sample map:** ``` { "total": "12000.0", "terms": “checking", "quote_id": "7605000000320001", "date": "2016-06-03", "quote_number": "EST-000026", "shipping_address": { "zip": "94588", "country": "USA", "address": "4910 Hopyard Rd", "city": "Pleasanton", "state": "CA", "fax": “Fax Number” }, "salesperson_name": “Salesperson”, "adjustment": "0.0", "currency_symbol": "Rs.", "salesperson_id": "7605000000336089", "currency_code": "INR", "shipping_charge": "0.0", "custom_fields": [ { "customfield_id": "7605000000190011", "is_active": true, "show_in_all_pdf": false, "value_formatted": "Check-6", "data_type": "autonumber", "index": 1, "label": "auto number", "show_on_pdf": false, "value": "Check-6" } ], "currency_id": "7605000000000099", "exchange_rate": "1.0", "status": "invoiced", "sub_total": "12000.0", "customer_name": “Customer”, "discount_amount": "0.0", "discount": "0.0", "tax_total": "0.0", "reference_number": “Ref number”, "notes": "Looking forward for your business.", "expiry_date": "2016-06-03", "customer_id": "7605000000258011", "billing_address": { "zip": "94588", "country": "USA", "address": "4910 Hopyard Rd", "city": "Pleasanton", "state": "CA", "fax": "Fax Number" } } ``` ##### Invoice The invoice map supports the following fields: Key Fields Description due\_date Invoice due date payment\_expected\_date Expected payment date for the invoice reference\_number Reference number of the invoice customer\_id Customer ID customer\_name Name of the customer who is assigned to the invoice currency\_id Currency ID currency\_code Currency code currency\_symbol Currency symbol exchange\_rate Exchange rate involved in the invoice discount\_amount Discount amount involved in the invoice discount Discount involved in the invoice shipping\_charge Shipping charge entered in the invoice adjustment Adjustments sub\_total Sub total of the invoice tax\_total Total tax amount in the invoice total Total amount balance Balance price\_precision Number of Decimal places billing\_address Billing address of the customer shipping\_address Shipping address of the customer notes Notes terms Terms and conditions custom\_fields Invoice custom fields salesperson\_id ID of the salesperson **Sample map:** ``` { "total": "0.0", "payment_terms": "0", "terms": “Checking”, "price_precision": "2", "payment_expected_date": "2016-06-31”, "date": "2016-06-30", "shipping_address": { "zip": "94588", "country": "USA", "address": "4910 Hopyard Rd", "city": "Pleasanton", "state": "CA", "fax": "Fax Number" }, "balance": "0.0", "adjustment": "0.0", "currency_symbol": "Rs.", "salesperson_id": “7605000000336089”, "currency_code": "INR", "shipping_charge": "0.0", "custom_fields": [ { "customfield_id": "7605000000336081", "is_active": true, "show_in_all_pdf": false, "value_formatted": "INV-8", "data_type": "autonumber", "index": 1, "label": "AutoNumber", "show_on_pdf": false, "value": "INV-8" }, { "customfield_id": "7605000000351027", "is_active": true, "show_in_all_pdf": true, "value_formatted": "01 Aug 2016", "data_type": "date", "index": 2, "label": "Date", "show_on_pdf": true, "value": "2016-08-01" } ], "currency_id": "7605000000000099", "exchange_rate": "1.0", "status": "draft", "sub_total": "12000.0", "customer_name": “Customer”, "invoice_number": "INV-000087", "discount_amount": "12000.0", "discount": "100.00%", "tax_total": "0.0", "reference_number": “checking”, "due_date": "2016-06-30", "invoice_id": "7605000000369043", "notes": "Thanks for your business.", "customer_id": "7605000000258011", "billing_address": { "zip": "94588", "country": "USA", "address": "4910 Hopyard Rd", "city": "Pleasanton", "state": "CA", "fax": "Fax Number" } } ``` ##### Sales Order Key Fields Description date Sales Order date tax\_total Total tax amount in the sales order zcrm\_potential\_id ID of the potential in Zoho CRM discount\_amount Discount amount involved in the sales order salesorder\_id Sales order ID discount Discount shipment\_date Date on which shipment is made billing\_address Billing address of the customer line\_items Line items currency\_code Currency code total Total amount delivery\_method\_id Delivery method ID terms Terms and conditions delivery\_method Method of delivery shipping\_address Shipping address of the customer exchange\_rate Exchange rate involved in the sales order currency\_symbol Currency symbol custom\_fields Sales order custom fields quote\_id Quote ID reference\_number Reference number of the sales order salesperson\_name Name of the salesperson involved salesperson\_id ID of the salesperson involved shipping\_charge Shipping charge entered in the sales order salesorder\_number Your sales order number sub\_total Sub total of the sales order zcrm\_potential\_name Name of the potential in Zoho CRM adjustment Adjustments made customer\_name Name of the customer who is assigned to the sales order customer\_id ID of the customer who is assigned to the sales order currency\_id Currency ID status Status of your sales order **Sample map:** ``` { "date": "2016-05-23", "tax_total": "0.0", "zcrm_potential_id": "", "discount_amount": "1200.0", "salesorder_id": "7605000000295003", "discount": "10.00%", "shipment_date": "2016-05-23", "billing_address": { "zip": "94588", "country": "USA", "address": "4910 Hopyard Rd", "city": "Pleasanton", "state": "CA", "fax": "Fax Number" }, "line_items": [ { "bcy_rate": 12000, "line_item_id": "7605000000295011", "quantity": 1, "item_id": "7605000000259147", "tax_name": "", "description": "", "discount": 0, "item_total": 12000, "item_custom_fields": [ ], "tax_id": "", "is_invoiced": true, "item_order": 0, "tags": [ ], "stock_on_hand": "", "unit": "", "rate": 12000, "tax_type": "tax", "name": "Moto", "tax_percentage": 0 } ], "currency_code": "INR", "total": "10820.0", "delivery_method_id": "7605000000461053", "terms": "Terms & Conditions", "delivery_method": "Door Delivery", "shipping_address": { "zip": "", "country": "", "address": "", "city": "", "state": "", "fax": "" }, "exchange_rate": "1.0", "currency_symbol": "Rs.", "custom_fields": [ { "customfield_id": "7605000000321009", "is_active": true, "show_in_all_pdf": true, "value_formatted": "Text", "data_type": "string", "index": 1, "label": "Text", "show_on_pdf": true, "value": "Text" } ], "quote_id": "7605000000405047", "reference_number": "Reference", "salesperson_name": "Arun", "salesperson_id": "7605000000135003", "shipping_charge": "10.0", "salesorder_number": "SO-00002", "sub_total": "12000.0", "zcrm_potential_name": "", "adjustment": "10.0", "customer_name": "Arun", "customer_id": "7605000000101007", "currency_id": "7605000000000099", "status": "invoiced" } ``` ##### Purchase Order The purchase order map supports the following fields: Key Fields Description date Date of the purchase order delivery\_address Delivery address tax\_total Total tax amount in the purchase order delivery\_org\_address\_id ID of delivery org address purchaseorder\_id Purchase order ID expected\_delivery\_date Expected delivery date billing\_address Billing address of purchase order line\_items Line items in the purchase order currency\_code Currency code total Total of the purchase order delivery\_customer\_id Delivery customer ID exchange\_rate Exchange rate involved in the purchase order currency\_symbol Currency symbol custom\_fields Purchase order custom fields ship\_via\_id ID of mode of shipping vendor\_name Name of the vendor reference\_number Reference number of your purchase order purchaseorder\_number Purchase order number delivery\_date Delivery date vendor\_id Vendor ID sub\_total Sub-total of the purchase order ship\_via Means of shipping attention Attention crm\_owner\_id ID of Zoho CRM owner currency\_id Currency ID status Status **Sample map:** ``` { "date": "2016-07-11", "delivery_address": { "zip": "94588", "country": "USA", "address": "4910 Hopyard Rd", "city": "Pleasanton", "state": "CA", "fax": "Fax Number" }, "tax_total": "0.0", "delivery_org_address_id": "7605000000054013", "purchaseorder_id": "7605000000378500", "expected_delivery_date": "", "billing_address": { "zip": "94588", "country": "USA", "address": "4910 Hopyard Rd", "city": "Pleasanton", "state": "CA", "fax": "Fax Number" }, "line_items": [ { "bcy_rate": 1000, "line_item_id": "7605000000378504", "quantity": 1, "item_id": "7605000000298021", "tax_name": "", "description": "", "item_total": 1000, "tax_id": "", "item_order": 0, "tags": [ ], "unit": "No", "account_id": "7605000000000403", "rate": 1000, "tax_type": "tax", "account_name": "Advertising And Marketing", "name": "Moto G Turbo Edition", "tax_percentage": 0 } ], "currency_code": "INR", "total": "1000.0", "delivery_customer_id": "", "exchange_rate": "1.0", "currency_symbol": "Rs.", "custom_fields": "[]", "ship_via_id": "7605000000461053", "vendor_name": "Mr. Vendor", "reference_number": "Reference", "purchaseorder_number": "PO-00006", "delivery_date": "2016-07-11", "vendor_id": "7605000000112009", "sub_total": "1000.0", "ship_via": "Door Delivery", "attention": "Arun", "crm_owner_id": "", "currency_id": "7605000000000099", "status": "billed" } ``` ##### Customer The customer map supports the following fields: Key Fields Description owner\_id ID of associated owner billing\_address Billing address associated to customer source Source of the customer contact\_id Contact ID payment\_terms Payments terms associated to customer currency\_code Currency code language\_code Language code contact\_type Type of the contact twitter Twitter info zcrm\_contact\_id ID of the contact in Zoho CRM shipping\_address Shipping address associated to customer pricebook\_id ID of pricebook associated contact\_name Name of contact website Website of contact owner\_name Name of contact owner currency\_symbol Currency symbol zcrm\_account\_id ID of Zoho CRM account custom\_fields Custom fields associated with customer facebook Facebook info pricebook\_name Name of pricebook associated primary\_contact\_id ID of primary contact company\_name Name of the company contact\_salutation Contact salutation crm\_owner\_id ID of CRM owner currency\_id Currency ID payment\_terms\_label Payment terms label status Status **Sample map:** ``` { "owner_id": "", "shipping_address": { "zip": "94588", "country": "USA", "address": "4910 Hopyard Rd", "city": "Pleasanton", "state": "CA", "fax": "Fax Number" }, "source": "user", "contact_id": "7605000000197147", "payment_terms": "0", "currency_code": "INR", "language_code": "en", "contact_type": "customer", "twitter": "", "zcrm_contact_id": "", "billing_address": { "zip": "94588", "country": "USA", "address": "4910 Hopyard Rd", "city": "Pleasanton", "state": "CA", "fax": "Fax Number" }, "pricebook_id": "", "contact_name": "Arun", "website": "www.zoho.com", "owner_name": "", "currency_symbol": "Rs.", "zcrm_account_id": "418070000000135001", "custom_fields": [ { "customfield_id": "7605000000063049", "is_active": true, "show_in_all_pdf": false, "value_formatted": "1234", "data_type": "number", "index": 1, "label": "Unpaid Invoices", "show_on_pdf": false, "value": "1234" } ], "facebook": "", "pricebook_name": "", "primary_contact_id": "7605000000197149", "company_name": "Zoho", "contact_salutation": "", "crm_owner_id": "", "currency_id": "7605000000000099", "payment_terms_label": "Due on Receipt", "status": "active" } ``` ##### Recurring Invoice The recurring invoice map supports the following fields: Key Fields Description end\_date End date of the recurring invoice profile tax\_total Total tax amount in the recurring invoice discount\_amount Discount amount involved in the recurring invoice repeat\_every Repetition period of recurring invoice profile discount Discount involved in the recurring invoice taxes Taxes associated with the recurring invoice billing\_address Billing address of the customer line\_items Line items in the recurring invoice payment\_terms Payments terms associated to customer currency\_code Currency code last\_sent\_date Date of the last sent invoice total Total amount recurrence\_name Name of the recurring invoice profile shipping\_address Shipping address of the customer next\_invoice\_date Date of the next invoice to be sent recurrence\_frequency Frequency of the recurring invoice profile recurring\_invoice\_id ID of the recurring invoice profile contact\_persons Contact persons involved in recurring invoice start\_date Starting date of the recurring invoice profile exchange\_rate Exchange rate involved in the recurring invoice currency\_symbol Currency symbol custom\_fields Recurring invoice custom fields salesperson\_name Name of the sales person involved salesperson\_id ID of the sales person involved shipping\_charge Shipping charge entered in the recurring invoice sub\_total Sub-total of the recurring invoice adjustment Adjustments made customer\_name Name of the customer involved customer\_id ID of the customer involved status Status of the recurring invoice profile **Sample map:** ``` { "end_date": "2016-10-15", "tax_total": "0.0", "discount_amount": "1.0", "repeat_every": "2", "discount": "1.00%", "taxes": "[]", "billing_address": {"zip":"","fax":"","address":"","state":"","country":"","city":""}, "line_items": [{"tags":[],"tax_name":"","tax_type":"tax","item_custom_fields":[],"product_type":"service","line_item_id":"348960000000103013","discount":0,"unit":"","item_order":0,"rate":100,"item_id":"","description":"%(d)%-%(m-2)%-%(y)%","name":"","quantity":1,"tax_id":"","tax_percentage":0,"item_total":100}], "payment_terms": "0", "currency_code": "GBP", "last_sent_date": "", "total": "200.0", "recurrence_name": "1", "shipping_address": {"zip":"","fax":"","address":"","state":"","country":"","city":""}, "next_invoice_date": "", "recurrence_frequency": "months", "recurring_invoice_id": "348960000000103005", "contact_persons": "[]", "start_date": "2016-01-07", "exchange_rate": "1.0", "currency_symbol": "£", "custom_fields": [{"value_formatted":"EST-001","index":1,"is_active":true,"data_type":"string","show_on_pdf":false,"value":"EST-001","show_in_all_pdf":false,"label":"Quote Number","customfield_id":"348960000000056001"},{"value_formatted":"15 Oct 2016","index":2,"is_active":true,"data_type":"date","show_on_pdf":false,"value":"2016-10-15","show_in_all_pdf":false,"label":"Date","customfield_id":"348960000000056003"},{"value_formatted":"true","index":3,"is_active":true,"data_type":"check_box","show_on_pdf":false,"value":true,"show_in_all_pdf":false,"label":"Invoice Factoring","customfield_id":"348960000000056079"},{"value_formatted":"£100.00","index":4,"is_active":true,"data_type":"amount","show_on_pdf":true,"value":100,"show_in_all_pdf":true,"label":"Amount","customfield_id":"348960000000060003"},{"value_formatted":"10%","index":5,"is_active":true,"data_type":"percent","show_on_pdf":true,"value":10,"show_in_all_pdf":true,"label":"Percentage","customfield_id":"348960000000060005"}], "salesperson_name": "Arun N", "salesperson_id": "348960000000111001", "shipping_charge": "100.0", "sub_total": "100.0", "adjustment": "1.0", "customer_name": "iArun", "customer_id": "348960000000051041", "status": "expired" } ``` ##### Expense The expense map supports the following fields: Key Fields Description date Date payment\_mode Mode of payment custom\_fields Expense custom fields vendor\_name Name of the vendor involved is\_billable Billability of the expense line\_items Line items in the expense project\_name Name of the project involved reference\_number Reference number of the expense currency\_code Currency code total Total project\_id ID of the project involved vendor\_id ID of the vendor involved sub\_total Sub-total on the expense customer\_name Name if the customer involved customer\_id ID of the customer involved expense\_id Expense ID currency\_id Currency ID **Sample map:** ``` { "date": "2016-10-08", "payment_mode": "Cash", "custom_fields": "[]", "vendor_name": "Vendor", "is_billable": "true", "line_items": [{"tags":[],"tax_name":"Standard Rate","item_order":1,"tax_type":"tax","account_id":"348960000000000400","description":"Notes","tax_amount":16.67,"product_type":"goods","tax_id":"348960000000044037","line_item_id":"348960000000184015","tax_percentage":20,"item_total":83.33,"account_name":"Office Supplies"}], "project_name": "", "reference_number": "12345", "currency_code": "GBP", "total": "100.0", "project_id": "", "vendor_id": "348960000000051033", "sub_total": "83.33", "customer_name": "Accounts", "customer_id": "348960000000111017", "expense_id": "348960000000184003", "currency_id": "348960000000000103" } ``` ##### Bill The bill map supports the following fields: Key Fields Description date Date on the bill bill\_id ID of the bill purchaseorder\_ids ID of the purchase order involved tax\_total Total tax amount in the bill exchange\_rate Exchange rate involved in the bill currency\_symbol Currency symbol custom\_fields Bill custom fields due\_date Due date of the bill vendor\_name Name of the vendor involved billing\_address Billing adress line\_items Line items in the bill payment\_terms Payments terms associated to vendor payment\_expected\_date Expected payment date reference\_number Reference number of the bill currency\_code Currency code total Total on the bill bill\_number Bill number payment\_made Payment made for the bill balance Balance amount recurring\_bill\_id ID of the recurring bill profile vendor\_id ID of the vendor involved sub\_total Sub-total on the bill status Bill status **Sample map:** ``` { "date": "2016-10-12", "bill_id": "348960000000193039", "purchaseorder_ids": "[]", "tax_total": "0.0", "exchange_rate": "1.0", "currency_symbol": "£", "custom_fields": "[]", "due_date": "2016-10-15", "vendor_name": "Vendor", "billing_address": {"zip":"","fax":"","address":"","state":"","country":"","city":""}, "line_items": [{"tags":[],"tax_name":"","project_name":"","tax_type":"tax","account_id":"348960000000000412","customer_name":"","is_billable":false,"product_type":"goods","line_item_id":"348960000000193047","invoice_number":"","sku":"","purchaseorder_item_id":"","account_name":"Credit Card Charges","unit":"1","item_order":0,"rate":33000,"bcy_rate":33000,"item_id":"348960000000087031","description":"","project_id":"","name":"refrigerator","tax_id":"","quantity":1,"invoice_id":"","tax_percentage":0,"customer_id":"","item_total":33000}], "payment_terms": "3", "payment_expected_date": "", "reference_number": "1", "currency_code": "GBP", "total": "33000.0", "bill_number": "Bill-001", "payment_made": "0.0", "balance": "33000.0", "recurring_bill_id": "", "vendor_id": "348960000000051033", "sub_total": "33000.0", "status": "open" } ``` ##### Recurring Bill The recurring bill map supports the following fields: Key Fields Description end\_date End date of the recurring bill profile tax\_total Total tax amount in the recurring bill exchange\_rate Exchange rate involved in the recurring bill custom\_fields Recurring bill custom fields repeat\_every Repetition period of recurring bill profile taxes Taxes involved in the recurring bill vendor\_name Name of the vendor involved line\_items Line items in the recurring bill payment\_terms Payments terms associated to vendor currency\_code Currency code last\_sent\_date Date of the last sent bill total Recurring bill total next\_bill\_date Date of the next bill recurring\_bill\_id ID of the recurring bill recurrence\_name Name of the recurring bill profile vendor\_id ID of the vendor involved sub\_total Sub-total on the recurring bill recurrence\_frequency Frequency of the recurring invoice profile payment\_terms\_label Payment terms label status Status of the recurring bill profile start\_date Starting date of the recurring bill profile **Sample map:** ``` { "end_date": "2016-10-15", "tax_total": "0.0", "exchange_rate": "1.0", "custom_fields": "[]", "repeat_every": "1", "taxes": "[]", "vendor_name": "Vendor", "line_items": [{"tags":[],"tax_name":"","account_id":"348960000000000403","tax_type":"tax","product_type":"goods","line_item_id":"348960000000193067","account_name":"Advertising And Marketing","unit":"","item_order":0,"rate":900,"bcy_rate":900,"item_id":"348960000000051011","description":"","name":"Item","quantity":1,"tax_id":"","tax_percentage":0,"item_total":900}], "payment_terms": "0", "currency_code": "GBP", "last_sent_date": "2016-10-12", "total": "900.0", "next_bill_date": "", "recurring_bill_id": "348960000000193061", "recurrence_name": "RB-001", "vendor_id": "348960000000051033", "sub_total": "900.0", "recurrence_frequency": "weeks", "payment_terms_label": "Due on Receipt", "status": "expired", "start_date": "2016-10-12" } ``` ##### Item The item map supports the following fields: Key Fields Description item\_id Item ID custom\_fields Item custom fields item\_type Type of the item tax\_name Name of the tax involved purchase\_rate Purchase rate of the item zcrm\_product\_id ID of the product in Zoho CRM tax\_id ID of the tax involved unit Unit of the item account\_id Sales account ID purchase\_account\_name Name of the purchase account purchase\_account\_id Purchase account ID tax\_type Type of the tax involved rate Sales rate of the item account\_name Name of the sales account involved name Name of the item tax\_percentage Percentage of tax involved pricebook\_rate Pricebook rate sku SKU of the item status Status of the item **Sample map:** ``` { "item_id": "348960000000051011", "custom_fields": [{"value_formatted":"100","index":1,"is_active":true,"data_type":"decimal","show_on_pdf":true,"value":100,"show_in_all_pdf":true,"label":"Profit","customfield_id":"348960000000134003"}], "item_type": "sales_and_purchases", "tax_name": "", "purchase_rate": "900.0", "zcrm_product_id": "1665395000000205001", "tax_id": "", "unit": "1", "account_id": "348960000000000388", "purchase_account_name": "Advertising And Marketing", "purchase_account_id": "348960000000000403", "tax_type": "", "rate": "1000.0", "account_name": "Sales", "name": "Item", "tax_percentage": "0", "pricebook_rate": "1000.0", "sku": "SKU", "status": "active" } ``` A few example explaining how these fields would help in fetching the necessary parameters: **Example 1:** To fetch quote id, use: ``` quoteid = quote.get("quote_id"); ``` **Example 2:** To fetch your organisation name, use: ``` orgid = organisation.get("name"); ``` **Example 3:** To fetch a user’s name and ZUID, use: ``` username = user.get("name"); zuid = user.get("zuid"); ``` To know more about how to use Deluge scripts for writing functions, refer the [Deluge Reference Guide](https://creator.zoho.com/learndeluge/#Welcome!). To know more about different scenarios where functions could be useful, refer our **[Function Scenarios](/ae/books/help/settings/automation-scenarios.html#custom-function-scenarios)** page. * * * ## Schedules Zoho Books lets you create and run predefined tasks at the specified time intervals using schedules. You can create your tasks using a deluge script and schedule this task to be executed at a particular time or on a recurring basis. **Note:** This feature is available only for certain plans of Zoho Books. Visit the [pricing page](https://www.zoho.com/books/pricing/) to check if it’s available in your current plan. ### Scenarios Here are a few scenarios where schedules can be created to execute custom actions. However, you can create custom schedules based on your firm’s requirements. **Scenario 1:** Peter runs a supermarket. At the end of every month, he wants to give a 10% off on the Next Purchase to customers whose total purchase for the month exceeds a certain amount, let’s say 1000. Peter creates a schedule to email this to selective customers on the last day of the month. **Scenario 2:** Peter uses a third party application for maintaining customer and employee database internally. He would like to sync all data from Zoho Books to the other application periodically. To do so, he creates a custom schedule to sync the data at 6 pm every day. **Scenario 3:** Peter sets a quarterly sales target for his territorial managers. Every four months, he has to send them their Profit and Loss reports and a congratulatory email when they have achieved their target or a motivating email for them to perform better. He writes a function and schedules it to be sent to his staff once every 4 months. ### Creating New Schedules To create a custom schedule: * Go to **Settings** on the top right corner of the page. * Select **Workflow Actions** under _Automation_. * In the _Workflow Actions_ pane, select **Schedules**. * Click **\+ New Schedule** in the top right corner. ![Create New Scheduler](/books/help/images/settings/scheduler-new.png) * On the _New Schedule_ page: * Enter a **Name** for your schedule. * Set the **Frequency** and recurrence pattern for the schedule to be executed. This can be daily, weekly, monthly or yearly. **Insight:** The recurrence pattern lets you decide when the custom schedule should be executed. You can choose to execute it on the set frequency. * Select how frequently the task should be executed. * **Daily**: The task will be executed every day (or based on your recurrence pattern). You can choose to exclude the weekends. ![Execute Daily](/books/help/images/settings/scheduler-daily.png) * **Weekly**: The task will be executed once a week. Select the day of the week on which the task should be executed. ![Execute Weekly](/books/help/images/settings/scheduler-weekly.png) * **Monthly**: Task will be executed once a month. This can be a specific date or a day in a month. For example, you can choose to execute it on the 5th of every month or the Second Saturday of every month. ![Execute Monthly](/books/help/images/settings/scheduler-monthly.png) * **Yearly**: Task will be executed once a year. You can select the month and specify the date of execution or specify the day. For example, the task can be executed on the first Sunday in January or just January 5. ![Execute Yearly](/books/help/images/settings/scheduler-yearly.png) * Set the **Start Date and Time**. **Warning:** The start date of a schedule cannot be more than one year from the creation date. * Select when the schedule should expire. It can expire after a number of executions or on a set date or not expire at all. ![Set Expiry](/books/help/images/settings/scheduler-expiry.png) * Drag and drop options to create a [****Deluge function****](https://www.zoho.com/deluge/help/) that will help to create your function. **Insight:** Deluge (Data Enriched Language for the Universal Grid Environment) is an online scripting language integrated with Zoho Services. It enables you to write your own functions that lets you modify the application to suit your needs, incrementally, making it more powerful and robust. * Click **Save** or **Save and Execute** to run it. ![Save Scheduler](/books/help/images/settings/scheduler-save.png) **Insight:** You can create a maximum of 10 custom schedules. ### Sample Function Here’s a sample function for [Scenario 1](/ae/books/help/settings/automation.html#scenario): ``` organisationID = organisation.get("organisation_id"); name = organisation.get("name"); orgEmail = organisation.get("email"); salesResponse = invokeUrl [ url: "https://books.zoho.com/api/v3/reports/salesbycustomer?organisation_id=" + organisationID + "&from_date=" + toStartOfMonth(today).toString("YYYY-MM-dd") + "&to_date=" + eomonth(today,0).toString("YYYY-MM-dd") type: GET connection: "books_api_connection" ]; salesDetails = salesResponse.get("sales").toList(); for each sales in salesDetails { amount = sales.get("sales_with_tax"); if(amount > "") { customerName = sales.get("customer_name"); customerResponse = invokeUrl [ url: "https://books.zoho.com/api/v3/contacts/" + sales.get("customer_id") + "?organisation_id=" + organisationID type: GET connection: "books_api_connection" ]; customerDetails = customerResponse.get("contact"); customerEmail = customerDetails.get("email"); sendmail [ from :zoho.adminuserid to :customerEmail subject :"Thank you for shopping! Here's a 10% discount!" message :"
Dear " + customerName + ",

We just wanted to take a moment of our time to thank you for your continuous support.

Based on your recent purchases, we'd like to offer you a 10% off on your next purchase with us. 

Please show this email during billing to avail this discount!

Regards,
" + name + "




" ] } } ``` ## Workflow Scenarios Workflows help you automate tasks in Zoho Books. [Read more](/ae/books/help/settings/automation-scenarios.html) to explore some common scenarios in detail. Learn more from the [Connections](https://www.zoho.com/ae/books/help/settings/connections.html) help document. Automate your business workflow with Zoho Books’ [accounting automation.](https://www.zoho.com/books/accounting-automation/) * * *