March 8, 2024

How To Call Another Deluge Function In Zoho CRM

Did you know that you can now use a single line of Deluge code in order to invoke other functions inside your Zoho CRM?

Previously to achieve this, you would have to expose your function via the CRM API and use an ‘invokeurl’ request to call your other function (if you still want to do it this way, the end of this article shows you how). However, there is now a much easier way:

otherFunctionResponse = standalone.MyOtherFunction(recordId);

Yep, that’s it! That’s all you need. This also works for functions that are used by buttons, workflows and schedules too (continue reading to see examples on how to use each of these). Using this approach can be a great way to split up your Deluge code into smaller functions, so that they become easier to manage and read.

Video Example

The rest of this blog post will explain how this line of code works, but here’s a video on the same topic if you would prefer to see it in action that way:

How It Works

Let’s go through each part of the code to explain what it is actually doing:

otherFunctionResponse

You can store the response that your other Deluge function returns into a variable. A scenario where this may be handy is if the other function you are calling encounters an error. You could then be made aware of that or check for specific errors in the parent function.

Note that only specific types of functions allow you to do this. The following types are the ones that are supported:

  • button
  • standalone

Trying to capture the response of other function types will return an error when you try to save your function in the Deluge editor.

standalone

This is the type of function that you wish to call. To find out what yours is in your CRM, go to Setup > Developer Hub > Functions. Find your function in the list that is returned. The text that is shown in the ‘category’ column will be the type you will need to use here.

The categories that are currently supported are:

  • automation
  • button
  • schedule
  • standalone

Note: This section of the code is case-sensitive. If you try to use ‘Standalone’ for example, you will be presented with an error when trying to save your function.

MyOtherFunction(recordId)

This is the ‘function name’ of your function, and it is how Zoho knows which other function you wish to call.

Note that this is not the ‘display name’, which can include spaces, but rather the internal name that you assign when creating the function.

You can find this name when you go to edit your function in CRM (see screenshot below).

You can also optionally pass through arguments to the other function, if the other function has them set up. In my example above, ‘recordId’ is a variable being passed through to the other function.

Examples

Here are some examples of how you might call each of the function categories:

automation.MyOtherFunction(recordId);
buttonResponse = button.MyCoolButton(recordId);
schedule.MyDailySchedule(recordId);
otherFunctionResponse = standalone.MyOtherFunction(recordId);

Detailed Example

In this scenario, let’s say you have a lookup on your Accounts module which stores the Primary Contact relating to that Account. There may be a number of fields from that lookup that you want to store on your parent Account record. Note that you can now use the CRM feature “Add field of lookup module”, which lets you bring in up to 5 fields from the lookup, but in some cases that may not be enough. Let’s say in this scenario you have a 6th field you want to use – Contact Email.

We want to retrieve this from our linked Contact and store it in a field called “Primary Contact Email”.

Below are the two functions that we need to achieve this – the first gets the Account record’s details, so that it can find the ID of the Primary Contact that is linked to it. It then passes that Contact ID to our second function, which deals with retrieving the Contact’s Email field. Once the first function has the response, it can then update the Primary Contact Email field with that information.

try 
{
    // Get the Account and the Contact lookup from it.
    account = zoho.crm.getRecordById("Accounts",accountId);
    contactLookup = account.get("Primary_Contact");
    if(isNull(contactLookup))
    {
        return "This Account does not have a Contact, so Primary Contact Email cannot be set.";
    }
    contactId = contactLookup.get("id");
    // This is how you call the other Deluge function.
    contactEmail = standalone.ArdGetContactEmail(contactId);
    // If response from other Deluge function is NOT an email, return response/error to user.
    if(contactEmail.notContains("@"))
    {
        return contactEmail;
    }
    // Save the Contact Email back to the Account record.
    updateAccountMap = Map();
    updateAccountMap.put("Primary_Contact_Email",contactEmail);
    updateResponse = zoho.crm.updateRecord("Accounts",accountId,updateAccountMap);
    return "Contact Email was updated successfully!";
}
catch (ex)
{
    return "An error occurred: " + ex;
}
return "";

Child function (standalone):

try 
{
    contact = zoho.crm.getRecordById("Contacts",contactId);
    contactEmail = contact.get("Email");
    return contactEmail;
}
catch (ex)
{
    return "An error occurred: " + ex;
}
return "";

Considerations

  • According to my testing, calling functions in this way does not work for categories that are of type ‘Related List’, ‘Signals’ or ‘Validation Rule’.
  • You may encounter issues if trying to delete a function that is being called/referenced in this way – in that scenario, you should first remove the reference to your other function, then it can safely be deleted.

The Original Approach

There are reasons why you might still want to use the traditional “API Key” approach, including if your function is being called from outside of the CRM. Here’s how you can do that instead:

    • In your CRM, go to Setup > Developer Hub > Functions.
    • Find the name of your function in the list, and hover over it with your mouse. Click on the 3 dots that appear next to the name, and click the ‘REST API’ option.
    • In the popup that appears, toggle on the ‘API Key’ option. Copy the URL that appears using the Copy button next to it, then click ‘Save’.
    • Next, in the other function you want to call this one from, you need to add an ‘invokeurl’ block to call this method, something like the following:
otherFunctionResponse = invokeurl
[
    url: "https://www.theurlyoujustcopied.com.au"
    type: GET
];

Keep an eye on our blog in the future for more Zoho CRM Deluge tips, tricks and implementation examples!

Simplify & Supercharge your Business with Zoho

Ready to see more? Ardento are your partners in innovation, adaption & growth, and we’re waiting for your call.