FAQs of Functions
1. Can you use a function within another function?
Yes, you can create a common standalone function to be used within multiple other functions and use the following syntax.
standalone.function_name()
2. How do I execute loop logic in a function?
You should create a list with entries corresponding to the number of iterations required to process all records. Refer to this Kaizen post for a real-time use case with Deluge function loops.
3. In Zoho CRM, are functions executed synchronously or asynchronously?
Functions in Zoho CRM are synchronous. When a Function is invoked, it starts executing, and the system remains in a waiting state until the function finishes its task before continuing with other operations.
4. How can I achieve asynchronous execution in Zoho CRM?
To handle asynchronous tasks in Zoho CRM, you can use Catalyst event listeners.
Use Case
Consider a scenario where a third-party application sends data to a custom function in Zoho CRM to create records and send emails. This function, set up as an automation, takes 20-30 seconds to run. However, the third-party app needs a response within 15 seconds to avoid an error. Automation functions only respond after completing their tasks. Is there a way for the function to send an immediate response while continuing to process the records and emails in the background?
Solution
You can achieve this asynchronous execution requirement by using Custom event listeners available in Catalyst.
By providing Custom event listener's invocation URL, you can send the data from the third party application to the custom event listener which in turn will invoke the Event function. In response, a 200 status code will be sent immediately, indicating the successful event creation. In the event function, you can code your custom logic to create records and send emails via Catalyst Java/NodeJS/Python SDK methods. This way, you can have your custom logic inside one single architecture, making it easier to manage the code, thus eliminating the need for splitting the function logic between multiple workflows.
Check this repository's ready-to-deploy sample code snippet . The README.md has the step-by-step guidance for the function to be created and hosted in Catalyst with very minimal effort using Catalyst CodeLib.