FAQs of Client Script
1. Where can you see the list of ZDKs supported by Client Script?
The Zoho Development Kit (ZDK) library comprises a rich set of Client and Web APIs that broaden the scope of Zoho Applications. You can utilize them to perform UI operations and trigger REST API calls. To view the documentation for ZDK, click the help icon in the Library under Information of the Client Script IDE.
2. Will the CRM API calls triggered from Client Script count into daily API limits?
Yes, every ZDK Web APIs in Client Script makes an API call to Zoho CRM and so every execution of a ZDK Web API affects the API limits.
3.What would be the correct way to set the value of a lookup field via Client Script?
You need to mention the id of the record along with the name when you try to set the value to a lookup field.
Example: Consider that there is a lookup field Category and the requirement is that it should be populated based on the Product selected by the user. Battery, Thermostat, and Ignition Switch belong to the category of Electrical Switches. Fuel level sensor, Light sensor, and Airbag sensor belong to the category of Sensors. i.e. If the user selects the product "Battery", then the lookup field Category should get auto-populated as Electrical Switches. Here is the code to accomplish this.
if (value.name == 'Airbag sensor' || value.name == 'Light sensor' || value.name == 'Fuel level sensor') {
//Populate value for lookup field Category based on the condition
ZDK.Page.getField('Category').setValue({ "id": "4967860000001049208", "name": "Sensors" });
}
else if (value.name == 'Ignition Switch' || value.name == 'Thermostat' || value.name == 'Battery') {
//Populate value for lookup field Category based on the condition
ZDK.Page.getField('Category').setValue({ "id": "4967860000001049217", "name": "Electrical Switches" });
}
4. How do I debug a Client Script in Zoho CRM?
You can use the log() statement to debug the script. The results of the execution of this log() statement will be displayed in the Messages panel of the Run option. Also, information about the execution status, logs, exception messages, and time taken for the execution are also displayed. For example, consider the following script. It has two log statements. You can view the output of the log statements in the messages panel of Run option.
var user = ZDK.Apps.CRM.Users.fetchById($Crm.user.id);
var field_obj = ZDK.Page.getField('Phone_Number');
log(field_obj.getValue());
log("Profile name of the user is "+ user.profile.name);
if(user.profile.name != 'Administrator')
{
field_obj.mask({ character: '*', length: 5, reverse: true });
}
Any CRM Operation performed inside the run mode will get reflected in your Zoho CRM account.
5. Does Client Script support languages other than Javascript?
No. Client Script in Zoho CRM supports only Javascript.
6. Will a Client Script run for all the layouts of the module?
No. Client Script will execute only for the layout specified while configuring the Client Script. If you want the script to run for other layouts or all the layouts of a module, you should create a separate Client Script for each layout.
7. What is the use of the Terminal section in the Client Script IDE?
You can execute the ZDK APIs instantly in the Terminal section of the Client Script IDE. For example, when you type the below script in the Terminal section and hit enter, you can see the alert message on the screen.
ZDK.Client.showMessage('Welcome to Client Script IDE', { type: 'info' });
8. When should you use onChange Page Event and onChange Field Event?
- Field Event - onChange
- If you want the script to run only when the specific field is updated, you can use the Field onChange Event.
- Page Event - onChange
- If you want the script to run whenever any of the fields on that page is updated, you can use the Page onChange Event.
- When you have to write a script for more than one field on the same page, you can use if and switch..case statements.
9. Using Client Script, how do I prevent the record from being saved when the value for a specific field entered is invalid?
To prevent a record from getting saved, you should follow the following steps: You need to use the onSave event type since you want to prevent the record from getting saved. Add the "return false;" statement. Always display the error/alert/message, so that the user will know the why the record is not getting saved.
Example: Consider that the field quantity should not have a value of less than 100. To accomplish this, you need to create a Client Script with the onSave event type, show an error message, and add a return false statement if the record should not get saved for that particular condition.
//Get the value of the field Quantity of Products
var qty_field = ZDK.Page.getField("Quantity_of_products");
log(qty_field);
//Invoke the static method by passing the value of Quantity of Products
if(qty_field.getValue() < 100)
{
qty_field.showError('The minimum value should be 100'); // or
// ZDK.Client.showMessage('The minimum value should be 100', { type: 'error' });//or
//ZDK.Client.showAlert('The minimum value should be 100');//or
return false;
}
10. What are all the places where the Client Script can run?
Currently, Client Script can be executed in the following pages.
- Create Page
- Edit Page
- Clone Page
- Detail Page (Canvas)
- Detail Page (Standard)
- List Page (Standard)
- Create Page (Wizard)
- Edit Page (Wizard)
11. Can Client Script run in Quick Create page?
No, currently Client Script in Zoho CRM cannot be executed in Quick Create Page.
12. Does the Client Script work with all the browser versions?
The Client Script in Zoho CRM is compatible with all the web browsers that are supported by Zoho CRM. You can find the list of supported browsers and their respective versions in this link.
13. What are all the supported events that trigger Client Script execution?
There is a set of events (user actions) available which trigger Client Script execution. Check out the list of supported events here.
14. How to get/set values in subform rows using Client Script?
You can use Form.getValues() and Form.setValues() to get/set values in subform or any other supported field in the current form. Also, check this sample code to know how to populate data in subform rows using Client Script.
15. Is it possible to display PDFs from third-party systems on Zoho CRM using Client Script?
You can display PDFs from third-party systems using Widget in Zoho CRM. It is possible to render widget with Client Script.
16. Can we use Client Script to display a custom HTML page or any third-party web pages within Zoho CRM?
Yes. It's possible by rendering a widget using Client Script. Please check out how to render a widget in Popup/ Callout / Flyout using Client Script.
17. Is it possible to dynamically populate data in fields based on other field inputs using Client Script?
Yes. It's possible. Check out this sample code which explains how to populate form data based on lookup field using Client Script.
18. Is it permissible to use window.localStorage for temporary storage of data?
No. Currently, It's not possible with Client Script.
19. Can we declare variables with 'let' and 'const' while writing a Script?
Yes. You can declare variables with 'var', 'let' and 'const' in Client Script. Moreover, all the core JavaScript features up to ES7 are supported
20. Is it possible to log the output obtained from the execution of Client Script in the console log of a web browser?
Yes. To log the output from the execution of Client Scripts, you can use either log() or console.log() method to output the data to the browser console.
21. Are async functions supported in Client Script?
Yes. Currently, all the core JavaScript features up to ES7 are supported.
22. Can custom events, in addition to standard events, be created to trigger Client Script Execution?
Unfortunately, it is not currently possible to create custom events to trigger Client Script Execution. As of now, only a limited set of CRM events are supported. Check out this Event Documentation to know more about Events that trigger Client Script Execution.
23. When invoking connections with Client Script, it is necessary to specify the 'param_type'. What are all the supported param types?
param_type = 1 → request parameter param_type = 2 → request body/payload
24. Is it possible to trigger the script on a field edit event in Zoho CRM?
Yes. You can use Field events which will trigger your script, when you enter/edit value in a field. Use this link to know more about these events.
25. Is it possible to set a value in Detail Page (Canvas) using Client Script?
Currently, Field edits (setValue( )) using Client Script is not supported in the fields of Detail Page (Canvas) and Detail Page (Standard). However, this feature is supported in the fields of Mandatory forms that are included in the Canvas/Standard Detail Page. As a workaround, you can use update record API to update the record in Detail Page (Canvas) along with $Client.refresh() method.
26. How to get values from a Lookup module?
To get value from the Lookup field, use ZDK.Page.getField('Lookup').getValue() method. Also, check out this sample code, in which we explain how to fetch values from the Lookup module and populate data in current Module.
27. What are all the supported operators for applying Lookup filter using setCriteria( ) method?
Currently, only the 'starts_with' and 'equals' operators are supported. However, we will support other operators as well soon.
28. Would the static resources uploaded in a Client Script be accessible throughout the entire organization, or would they only be accessible within the module or page where they were uploaded?
Static Resources, once added, will be available to all the scripts in that particular page. Users can add these resources to their scripts and use them. Click here to learn more about Static Resources.
29. Do we need to save the script before testing it during runtime?
You don't need to save the code to test the script in Run mode.
30. Is it possible to disable custom buttons?
Yes. It is possible to enable/disable custom buttons as well as system buttons.
31. Can we use Client Script in canvas Detail page?
Yes. Client Script can be used in multiple pages such as Create Page, Edit Page Clone Page, Detail Page (Canvas), Create Page (Wizard), Edit Page (Wizard), List Page (Standard) and Detail Page (Standard). Click here to learn more about it.
32. Does Client Script support Contextual Multi-select lookup filter?
Currently, Contextual filter can be applied in Single Lookup field and it will be supported in Multi-select lookup field as well soon.
33. Can we import custom libraries in Client script?
Yes. We can upload it as a static resource and use it in the script.
34. Is it possible to fetch data from a third-party service and auto-populate response in the respective fields in Zoho CRM using Client Script?
Yes. Users can use Client Script to fetch data from a third-party service by making third party API call and populate data in the field. The script can make calls only to the domains added to the Trusted Domains list. Check out this sample to learn how to achieve it with Client Script.
35. What does getForm() method do?
The getForm() method can be used for getting all the fields from current form (like Create Page, Clone Page etc.,). You can even set values to multiple fields in a Page with the help of getForm().setValues() method.
36. Can a Lookup field be filtered contextually based on two other fields using Client Script?
Yes. It is possible to apply filter based on the values of two other fields using Client Script.
37. Can we either disable the delete button or is it possible to perform validation before deleting a record?
Yes. You can disable the delete button using Client Script, but for now, it's not possible to perform validation before deleting a record.
38. Is it possible to display custom messages when hovering over fields? Also, Is there any event available for mouse hover in Client Script?
The addTooltip() method can be used to show a custom message for a specific field when hovered over with a mouse. However, currently there is no event available for mouse hover in Client Script.
39. Can I include a copy feature using a custom icon in canvas with Client script?
This feature is under development.
40. Is it possible to create forms using the dynamic field values in CRM using Client Script?
You can make use of getInput() method to make a form with pseudo fields based on Dynamic field values. Also, you can render a Widget to create a form and then pass the data to the Page using Client Script. It is also possible to hide/show the fields in the Page based on Dynamic values using setVisibility() method in Client Script.
41. In the future, will it be possible to include formatted text in a Flyout without having to render a widget?
We will check on the feasibility of providing this support.
42. Consider a Client Script is triggered on a field edit event in Detail Page (Standard). In such a case, either will it reflect the changes in another field linked with this field or will it need a page reload? Eg. Age field population based on DOB.
When a field is updated in detail Page (Canvas), the linked field will only be updated after the page is reloaded. To reload the page in the Detail Page (Canvas), you can use the $Client.refresh() method. This support will be available in Detail Page (Standard) soon.
43. Is there an execution timeout for Client Script?
Yes, Client Script enforces a 10-second execution timeout. Whenever your script exceeds this execution time you can handle it using a loader. Click here for more details.