Kaizen#75 - Frequently Asked Questions on Client Script

Kaizen#75 - Frequently Asked Questions on Client Script

Welcome to another week of Kaizen! In this post, let us discuss some of the frequently asked questions in 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 API 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" });

    }


Here is how the above script works.



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
Page Event - onChange
If you want the script to run only when the specific field is updated, you can use the Field onChange Event.

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 "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;
}


Here is how the above script works.



10. What are all the places where the Client Script can run?
Currently, Client Script can be executed in the following pages of Zoho CRM.
  • Create Page
  • Edit Page
  • Clone Page
  • Detail Page (Canvas)
  • 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 Client Script support the Detail Page (Standard)? 

Currently, there is no support for the Detail Page (Standard) but it is in our roadmap.
Once this goes live, you will also be able to hide fields.







                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation


                                        Manage your brands on social media



                                              Zoho TeamInbox Resources

                                                Zoho DataPrep Resources



                                                  Zoho CRM Plus Resources

                                                    Zoho Books Resources


                                                      Zoho Subscriptions Resources

                                                        Zoho Projects Resources


                                                          Zoho Sprints Resources


                                                            Qntrl Resources


                                                              Zoho Creator Resources


                                                                Zoho WorkDrive Resources



                                                                  Zoho Campaigns Resources

                                                                    Zoho CRM Resources

                                                                    • CRM Community Learning Series

                                                                      CRM Community Learning Series


                                                                    • Tips

                                                                      Tips

                                                                    • Functions

                                                                      Functions

                                                                    • Meetups

                                                                      Meetups

                                                                    • Kbase

                                                                      Kbase

                                                                    • Resources

                                                                      Resources

                                                                    • Digest

                                                                      Digest

                                                                    • CRM Marketplace

                                                                      CRM Marketplace

                                                                    • MVP Corner

                                                                      MVP Corner

                                                                    





                                                                    




                                                                        Design. Discuss. Deliver.

                                                                        Create visually engaging stories with Zoho Show.

                                                                        Get Started Now