Kaizen# 83: Get input via pop-up and show/hide fields in Client Script

Kaizen# 83: Get input via pop-up and show/hide fields in Client Script

Hello everyone!
Welcome back to another Kaizen post.

In this post, let us discuss the following use cases.

 A. How to get input via a pop-up

1. Requirement 

Consider that the requirement is to display a pop-up whenever a Salesperson changes the "Stage" of the deal. The Salesperson should be able to add comments in that pop-up. This comment should be populated to the field "Description" along with the name of the "Stage" and it should keep appending the comments whenever there is a change in Stage.

Solution

The script should execute whenever the salesperson selects the field "Stage". So create a Client Script on Create Page of the Deals module.

  • Go to Setup > Developer Space > Client Script. Click +New Script.
  • Specify the details to create a script and click Next.

  • Enter the following script and click Save.

var notes_pop_up = ZDK.Client.getInput([{ type: 'text', label: 'Comments' }], 'Deal', 'OK', 'Cancel');
var notes_field = ZDK.Page.getField("Description");
if (notes_field != null) {
var desc = notes_field.getValue() + " " + value + "- " + notes_pop_up +",";
    notes_field.setValue(desc);
}

  • The getInput() ZDK enables you to show a pop-up on screen. You can add fields with labels in this pop-up. The field that appears in this pop-up is a pseudo field and is not a real field in the Deals module. It will appear only when Client Script executes and you can use it in the script. Such pseudo fields are highly beneficial when you want to manipulate/calculate data based on user input as it does not affect the module's field limits of Zoho CRM. 

Syntax of getInput() : 
  • getInput(options, heading, accept_message, reject_message) → {Object}
Parameters:
  • options   - Input options (Maximum number of options is 7).
  • heading - Heading of the pop-up.
  • accept_message - Text for accepting message.
  • reject_message - Text for rejecting message.

Here is how the Client Script works,




B. How to hide and show fields using Client Script

1. Requirement 

To hide the field "Expected Revenue" when the status of the Deal is "Needs Analysis".

Solution

This script should run whenever the salesperson updates the field "Stage". So create a Client Script on Edit Page of the Deals module.

  • Go to Setup > Developer Space > Client Script. 
  • Click +New Script.
  • Specify the details to create a script and click Next.

  • Enter the following script and click Save.

var stage_field = ZDK.Page.getField('Stage').getValue();
log(stage_field);
var field_obj = ZDK.Page.getField('Expected_Revenue');
if (stage_field == 'Needs Analysis') {
    field_obj.setVisibility(false);
}
else
field_obj.setVisibility(true);
}

Syntax
  • setVisibility(value)
Parameters
  • value - visibility attribute of the field input(true/false)

Here is how the Client Script works.




We hope you found this post useful. We will meet you next week with another interesting topic!
If you have any questions let us know in the comment section.
Click here for more details on Client Script in Zoho CRM.


    Access your files securely from anywhere

        Zoho Developer Community




                                  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 Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • 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