Zoho CRM Standalone Functions
Standalone functions in Zoho CRM allow you to execute a function within another function. There are many practical use cases for standalone functions within Zoho CRM, including removing duplicate code and code reuse.
This discussion will cover how to use and implement Zoho CRM standalone functions. There are two main methods for using and implementing standalone functions:
- No Parameters
- With Parameters
No Parameters
We will first show how to execute a standalone function without any input parameters. This is the easiest way to execute these functions.
Setting Up Standalone Function
To setup a standalone function:
- Go to Setup -> Functions -> New Function
- Name the function and under Category select Standalone. Click Next.
- You'll be taken to the Deluge code editor.
Edit your standalone function as below :
- /* STANDALONE FUNCTION */
- response = 'This is a test.';
- return response;
- Click Save & Execute.
Your custom function is ready to be called using the standalone namespace.
Setting Up Requesting Function
To setup a requesting function:
- Go to Setup -> Functions -> New Function
- Name the function and select any Category. Click Next.
- You'll be taken to the Deluge code editor.
- /* REQUESTING FUNCTION */
- standalone_function_values = standalone.my_standalone_function();
- info standalone_function_values;
- Click Save & Execute.
When you execute this requesting function, you should see the response from the standalone function printed console messages:
- /* CONSOLE */
- Info
- This is a test.
- Function executed successfully.
You can access futher JSON reponse messages from the page inspector, under Network -> Fetch/XHR -> Response. The page inspector needs to be opened prior to hitting "Save & Execute" to see these responses.
- /* EXAMPLE NETWORK RESPONSE FROM PAGE INSPECTOR */
- {
- "result": {
- "Tasks": [],
- "message": {
- "userMessage": [
- "This is a test."
- ]
- }
- },
- "unique_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
- "code": XXXX,
- "function_id": "XXXXXXXXXXXXXXXXX",
- "message": "Function Executed Successfully",*
- "status": "Success"
- }
With Parameters
We will now show how to execute a standalone function with simple input parameters.
Setting Up Standalone Function
To setup a parameterised standalone function:
- Go to Setup -> Functions -> New Function
- Name the function and under Category select Standalone. Click Next.
- You'll be taken to the Deluge code editor.
- ---------------------------------
- PARAMETERS
- record_id: STRING
- ---------------------------------
Edit your standalone function so that it is just:
- /* STANDALONE FUNCTION */
- response = zoho.crm.getRecordById("[Zoho Module]", record_id);
- return response;
- Click Save.
Your custom function can now be requested by another function using the standalone namespace.
Setting Up Requesting Function
To setup a requesting function:
- Go to Setup -> Functions -> New Function
- Name the function and select any Category. Click Next.
- You'll be taken to the Deluge code editor.
- /* REQUESTING FUNCTION */
- standalone_function_with_parameter_values = standalone.my_standalone_function_with_parameter(record_id);
- info standalone_function_with_parameter_values;
- Click Save & Execute.
When we execute the requesting function, enter the record_id from the relevant Zoho Module, you should see the following printed console messages:
- /* OUTPUT */
- Info
- {List, map or value should be returned to the console}
- Function executed successfully