Triggering Function from Notes in Zoho CRM

Difficulty: Intermediate
Estimated reading time: 30 mins
Estimated implementation time: 1 hour

Unlike other modules in CRM, Workflow Rules doesn’t allow you to set “Notes” as a function trigger. Till that day arrives, we have found a workaround that enables function triggering from Notes (create/edit). Here’s the idea:

  • Enable Notifications in CRM sends a webhook to Zoho Flow on trigger of Notes (edit/create).
  • Zoho Flow receives and interprets the data package, then sends the ID to a serverless function in CRM.
  • Serverless Function receives the ID and executes the custom function.

Cool Ideas to Use the Function

Here’s an example of an application. Suppose keeping Notes in a Deal is a mandatory procedure when it comes to following up on Deals in your organization. You need to know when a Deal was last “followed-up” to review dormant Deals. You can’t rely on “Last Activity Time”, because you have a daily scheduled function that updates a custom field in Deals. You need to know the time stamp of when a Note is last created/edited in the Deal.

Configuration

 The following Zoho CRM Connection scope is needed:

  • ZohoCRM.notifications.ALL

This set up requires you to frequently toggle between CRM and Flow, so it’s a good idea to have 2 tabs/windows open for each app.

Create a Zoho Flow Webhook

Log in to Zoho Flow and create a new Flow based on this settings:

  • Create Flow -> Webhook -> Payload Format (JSON)
  • Once this is done, COPY the webhook that you have created.

Enable Notifications

Notification APIs allow you to get instant notifications whenever an action is performed (create/update/delete) on the records of a module. The system notifies you of the event to the URL provided. The Zoho Flow webhook that you have created will be set as the URL here.

  • channel_id
    • The given value is sent back in notification URL body to make sure that the notification is for a particular channel. Can be any arbitrary number.
  • events
    • The module action(s) for triggger (Module.action). The possible actions are create/edit/delete.
  • channel_expiry
    • Notifications expiry time. Maximum of only one day from the time they were enabled. If it is not specified or set for more than a day, the default expiry time is for one hour. Accepts only Zoho date-time format.
    • Here, we would want to set the maximum expiry (1 day after enabling notifications) and have a scheduled function to run daily so that the notification stays active at all times.
    • Check out this post on how to get the current Zoho date-time and convert it into a parseable format for update.
  • notify_url
    • URL to be notified (POST request). Whenever any action gets triggered, the notification will be sent through this notify url.
    • Insert the Zoho Flow Webhook URL here.
				
					param = 
{
  "watch":
   {
     {
        "channel_id":"1",
        "events":{"Notes.create","Notes.edit"}, 
        "channel_expiry":"INSERT_DATE_TIME_HERE",
        "notify_url": "INSERT_ZOHO_FLOW_WEBHOOK_HERE"
     } 
   }
};

response = invokeurl
[
	url :"https://www.zohoapis.com/crm/v2/actions/watch"
	type :POST
	parameters:param + ""
	connection:"INSERT_ZOHO_CRM_CONNECTION_HERE"
];
info response;
				
			

Note: To check if your notification is active, you can use the notification details API.

Test the Webhook on Zoho Flow

Now that you have enabled notifications, you can test the signal by clicking Test the Webhook in Zoho Flow, then create/edit a CRM note. On success, you will be able to see the payload data.

Trying to learn Zoho? Check out some courses

Create a Serverless Function
in Zoho CRM

If you’re not familiar with the idea of a serverless function, please refer to this post.

  • In the serverless function, set crmAPIRequest as a string argument. Assuming that all you need here is the information of the Note record, you can just get the ID, then use a getRecordsbyID function to fetch the record details.
  • Note: When you do crmAPIRequest.get(“body”), it will return you the ID in a form of a list. To get the ID, .get(0) is used to get the first index.

Once you have the ID, you can program any actions you want in this serverless function. However, the set up is not yet complete. For this to work, we need to send the ID from Flow to the serverless function that we’ve made.

Go out of the function, click on the ellipsis and select REST API. Switch on the API KEY and COPY the URL.

Write a Custom Function
in Zoho Flow

Go back to Zoho Flow, and in the Flow Builder, create a custom function by going to Logic > + Custom Function.

  • Name the function.
  • Leave return type as void.
  • Set the Input Parameters as id with string as its data type and hit create.
  • Insert the script below into the function, save it, and link to your Flow (select the id at the payload when you link the flow to the logic).

If you’re not familiar with Zoho Flow, here’s the GIF walkthrough.

Once this is done, you’re now ALL SET! Whenever a Note is created/edited, CRM sends the Note ID to Zoho Flow which then sends and executes the serverless function.

TIP: To test that the setup is working properly, you can add a sendmail function to send the response to your email in your serverless function script.

Click here to copy these scripts. For more Zoho-wizardry, check out our GitHub page.

More Free Resources

Deluge Tips – Null Check

When scripting, ask yourself this question – will this value ever be null? If it’s a yes, that’s a place for a null check! Here are 3 tips and best practices to help you kickstart the habit.

Read More »