Hello everyone!
Welcome back to another interesting post. In this post, let us see how you can render Widgets using Client Script.
Widgets are
embeddable UI components that you can create and add to your Zoho CRM. You can use widgets to perform functions that utilize data from
third-party applications. You can build widgets for Zoho CRM using our
JS SDK.
You can render a Widget through
Client Script and pass data from the Widget to the Client Script.
Use Case:
At Zylker, a manufacturing company, the Service Agent places orders using the Orders module. There is a sub-form named Product list. The user should add the products by clicking the "Add row" button every time.

To avoid this, Zylker wants the users to select multiple products from a single pop-up. Once the user selects the products from that pop-up , the sub-form "Product list" should get updated with all those products(one product in one sub-form row).
Solution:
Whenever the user picks the Product Category, you can create a Client Script to render the widget. The Products selected by the user on the widget , will be passed to the Client Script and will be added as separate rows in Product list subform.
1. Install Zoho CLI and add code to the app folder.
2. Upload the zip file as a Widget.
3. Create a Client Script to render the Widget and to add data to the Sub-form.
1. Install Zoho CLI and add code to the app folder
Follow the steps given in this
post and add the
html code, javascript file and css file.
Index.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Choose products</title> <link href="styles/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="wgt_cp_popupContent"> <section class="wgt_cp_contentWrap"> <div hidden="true" id="noProductDiv"> <pre>No products associated to the selected deal</pre> </div> <table width="100%" cellspacing="0" id="pTable"> <thead> <tr class="wgt_productTblHead"> <th><input type="checkbox" id="selectAll" onclick="selectAllProducts(this)"></th> <th>Product Name</th> <th>Product Category</th> <th>Unit Price</th> <th>Quantity in Stock</th> </tr> </thead> <tbody id="tbody"></tbody> </table> </section> </div> <script src="./script/script.js"></script> </body> </html> |
Script.js
var count = 0; var productData, maxRows = 0; ZOHO.embeddedApp.on("PageLoad", async function (data) { console.log("data from Client Script", data); maxRows = data.max_rows; const search_response = await ZOHO.CRM.API.searchRecord({ Entity: "Products", Type: "criteria", Query: "(Product_Category:equals:" + data.product_category + ")" }) if (search_response && search_response.data && search_response.data.length) { productData = search_response.data; var htmlString = ""; productData.forEach(({ id, Product_Category, Product_Name, Unit_Price, Qty_in_Stock }) => { htmlString = htmlString.concat( `<tr> <td><input type='checkbox' onclick='selected(this)' id='${id}' class='products'></td> <td>${Product_Name}</td> <td>${Product_Category}</td> <td>${Unit_Price}</td> <td>${Qty_in_Stock}</td> </tr>` ); }); document.getElementById("tbody").innerHTML = htmlString; } else { document.getElementById("pTable").hidden = true; document.getElementById("noProductDiv").hidden = false;} }); ZOHO.embeddedApp.init(); function selected(element) { element.checked ? count++ : count-- ; document.getElementById("selectedCount").innerHTML = `${count} Products selected`; } function closewidget() { if (count > maxRows) { alert("Selected product is greater than the maximum subform rows."); } else { var selected_products = []; for (product_element of document.getElementsByClassName('products')) { product_element.checked && selected_products.push(productData.find(product => product.id === product_element.id));} console.log("returning to Client Script ...", JSON.stringify(selected_products)); $Client.close(selected_products);} } |
As per the above script, the products are fetched from the "Products" module based on the "Product Category" selected by the user. This information is captured in "search_response" and is added to the body of widget.html.
Here, the code
$Client.close(selected_products); will pass the selected products from Widget to the Client Script and close the widget rendered from Client Script.
Click here for more details about the variable $Client.
Next step is to upload the zip file of the app folder.
2. Upload the zip file as a Widget
- Go to Setup > Developer Space > Widgets.
- Click Create New Widget.
- The Hosting should be "Zoho" and mention the html page of the app folder that you uploaded.
Note: The widget should be of "button" type in order to render through a Client Script.
3. Create a Client Script to render Widget and to add data to the subform
- Go to Setup > Developer Space > Client Script. Click +New Script.
- Specify the details to create a script and click Next.
- The Client Script should render the Widget when the user selects Product Category. So Client Script should have field event on the field "Product Category".
- On the Client Script IDE, you can see the below details.
- Enter the following script in the Client Script IDE and click save.
var products_list = ZDK.Page.getField('Product_list').getValue(); if (products_list.length === 1) { // Clear subform if empty row !Object.values(products_list[0]).every(value => !!value) && products_list.pop(); } // Open widget with product category & max. allowed rows based on existing subform data var selected_products = ZDK.Client.openPopup({ api_name: 'choose_products', type: 'widget', header: 'Choose Products', animation_type: 1, height: '570px', width: '1359px', left: '150px' }, { product_category: value, max_rows: 25 - products_list.length }); // Update subform with Selected Products from the widget Popup if (selected_products.length) { selected_products.forEach(product => { products_list.push({ Product_Name: { id: product.id, name: product.Product_Name }, Quantity: 1, Unit_Price: product.Unit_Price }); }); ZDK.Page.getField('Product_list').setValue(products_list); }
|
- To render a widget from Client Script, use openPopup(config, data) ZDK. You can specify the configuration details like api name of the widget, title, size, animation type as parameters and specify the data to be passed as 'PageLoad' event data in the Widget.
- The response from the widget (i.e user selection) is captured by the variable "selected_products". Then each product (id,name,product_name,quantity and unit_price) is pushed to the list products_list. Finally, the product list value is updated to the Product Category sub-form using setValue(value) ZDK.
- Here is how the Widget gets rendered through Client Script.
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.
As we approach the
100th post in our Kaizen series next week,
we invite you to share your queries and concerns with us. We are always looking for ways to improve our content and make it more relevant to our readers.
Please fill out this
form to share your thoughts.
Happy Coding!
Recent Topics
Tip #42 – How to manage data security with Privacy Settings – 'Insider Insights'
Data privacy is a cornerstone of trust in remote support. Through Privacy Settings in Zoho Assist, you can set up how data is gathered, stored, and handled in your organization. These settings ensure compliance, data protection for sensitive details,
Zoho DataPrep and File Pattern configuration
I'm using Zoho data prep to ingest data from One Drive into Zoho Analytics... The pipeline is super simple but I can't any way to get all the files that I need. Basically I need to bring all the files with a certain pattern and for that I'm using a regex
Introducing Dark Mode / Light Mode : A New Look For Your CRM
Hello Users, We are excited to announce a highly anticipated feature - the launch of Day, Night and Auto Mode implementation in Zoho CRM's NextGen user interface! This feature is designed to provide a visually appealing and comfortable experience for
Quick Item Search & Auto-suggestion for Invoices
Hi Team, I am facing an issue while creating invoices in Zoho Books. Currently, I have to type the full item name in the correct sequence and spelling for it to appear. For example, my item name is: "Distemper Acri Silk Special White 10kg" If I type something
Ticketbai! en el Pais Vasco
Hola a todos, En enero de 2.022 se va a implantar en el país vasco un nuevo sistema de facturación, denominado ticketbai!, ¿hay alguna previsión de realizar las adaptaciones en zoho books o zoho invoices? Ignoro la cantidad de clientes que tienen estas
Zoho CRM mobile app feature update: home page widgets, field tooltips and user image upload
Hello everyone! Your business doesn't pause when you're on the move, and neither should your CRM. That's why in our latest update, we've introduced a few new features to make your mobile CRM experience smoother and more efficient. Let's take a quick look
Zoho CRM Plain Text Template: Line Breaks and Formatting Issue
Hello, I'm following the instructions to create email templates in Zoho CRM, but I'm having a problem with the plain text version. https://help.zoho.com/portal/en/kb/zoho-sign/integrations/zoho-apps/zoho-crm/articles/zoho-crm-email-templates#Steps_to_create_a_custom_email_template
Optimizing Task Handling: Auto-Remove Recurrence for cancelled Tasks.
Hello Everyone, A Custom function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it. Requirement:
Important updates to your connectors
Hello everyone, Greeting from Zoho Creator! We're excited to announce that we'll be rolling out significant backend updates to Zoho Creator's built-in connectors to enhance security by following the latest frameworks. The existing version of some of the
Create, collaborate, and manage agreements with Zoho Sign
Agreements drive business. We launched Zoho Sign in 2017 as a simple digital signature tool to sign agreements from anywhere, at any time. Over the years, we've learned that most agreements go through last-minute changes before they're signed. Our users
Function #25: Automatically generate purchase orders from a sales order
We kicked off the "Function Fridays" series with the goal of helping you automate your everyday accounting tasks. As we delve into today's post, I'm delighted to announce that we're here to present the 25th custom function in this series. While it is
DNS set up
I want to create an email with my company domain. When I tried to add new record with cloudflare it didn't work. The DNS record can't be manually added. I followed the instruction but still can't add it. Could you help?
hiding a topic from all but one segment (or list)
My organization sends out a number of newsletters using Zoho Campaigns. One of those newsletters is for volunteers. In order to become a volunteer, a person has to first go through our volunteer orientation (training). After that, they can receive newsletters
How do I set up this automation correctly?
When contacts enter my Subscribers list, I want it to reference a custom field to see if it is empty. Then I want it to do two things: If empty: Assign a tag based on a different custom field. If that custom field is empty, assign a different tag. If
Function #62: Display associated Quote on Invoice details screen
Hello everyone! Today, we are sharing a Related List script that makes it easy to view and access the quote from which an invoice was created right from the invoice details screen. This Related List displays the Quote number and Amount, allowing you to
Desk x CRM Integration
Howdy! We currently use SalesIQ but we are considering moving across to Desk as it seems to have more functionality that we want. One of the pulls is the ability for our customers to self serve. But, I might be getting over excited and not actually need
Function #53: Transaction Level Profitability for Invoices
Hello everyone, and welcome back to our series! We have previously provided custom functions for calculating the profitability of a quote and a sales order. There may be instances where the invoice may differ from its corresponding quote or sales order.
Issue with Save & Share Link – Works for Others but Not Creator
I’ve enabled the "Save and Share" feature in Zoho Forms, and it works correctly for all users accessing the public link—except for me (the form creator). Issue Details: When I save and share the link, recipients see a “no permission” error. The form is
Save the pdf report from a registration form in a Folder
Through Zoho Forms I created a registration form with quite a lot of rules to handle different variables (TEAM types, payment in installments, etc.), and the result is pretty good. The automatic PDF that is sent to the respondent upon submission is already
zoho forms integration to zoho work drive
Scenario: A user fills out a Zoho Form, entering details such as email, mobile number, and other required information, and uploads supporting documents like PAN, Aadhaar, etc. Upon submission, the data is available in Zoho Forms Reports. Requirement:
Zoho Forms to Zoho CRM Integration failed - can I restart it?
The integration of Zoho Form to Zoho CRM has failed. Is there a way for me to restart it for the impacted entry?
insert an equation, but in document, it shows an image not available.
I'm new to Zoho writer and used Zoho writer in desktop app version . When I inserted an equation, I got an image not available sign. Any help is appreciated. Thanks, Charles
Zoho Desk Android app update - Swipe action customization
Hello everyone! We have brought in support for the swipe action customization in latest version(v2.9.13) of the Zoho Desk Android app update, enabling you to configure left and right swipe gestures on tickets to carry out the actions swiftly without opening
Import KB template OR Export template for zoho desk?
Greetings. Can you tell me if there is a way to get an EXPORT of my KB articles? OR is there a template you supply for importing KB articles into my zoho desk? I am looking for a method of understanding what fields can be imported, and what their possible
XML format to import knowledgebase into Zoho Desk
Hi, We just started to use Zoho Desk and want to import our knowledgebase from our old support system (Freshdesk) to Zoho Desk. Can anyone give us information about the format of xml file to import? There is no explanation on the related page.
Zoho Desk integration with Power BI
Hi, I want to be able to create a Power BI report which has live updates of ticket data from zoho desk, is this possile at all? Thanks Jack
Arranging Ticket Templates
Is there any way to arrange our ticket templates? It doesn't look very organised when it's just arranged according to when they were created. We want the list to look more organised, by arranging/grouping them by topics, or even just by alphabetical
What they mean with "Portal"?
I just downloaded this app to take my personal notes on digital art studio because it seemed to me the most comfortable app to do it, I use it very often, what do they mean by “no activity on your portal”? I have about 1 year of work here and I don't
favorites no longer listed
Hello, I can no longer navigate to my Favorites from the pulldown at the top of my grid view (see attached screenshot). I wasn't able to find it anywhere! Please help me display my Favorites. Thank you!
Notecards Disappeared
Got a new phone. Downloaded and signed in Zoho Notebook. Not finding the Note cards. Just Empty Note books. Frustrating.
Table Errors
Hello, I'm new to Zoho Notebook and using it on several Mac/Apple devices. My question is regarding tables: Why do they become broken, and how to fix the error without retyping all my data? (Please see the screenshot attached.)
Online Calculator with Zoho Forms?
I'd like to build a custom calculator on my website. Zoho Forms seems to offer all the fields for basic calculations performed live without pressing any "Calculate" buttons. Unfortunately, there is still that "Submit" button at the bottom. There is nothing
Zoho Tables instead of Zoho Creator Spreadsheet reports <3
That would make my day for sure. Zoho Creator is create, but miss data entering as AirTable/Spreadsheet can. Seeing Zoho putting effort in this makes me think maybe one day we could see a similar interface for Zoho Creator spreadsheet reports. B.
Notebook Stack
Hi Everyone I Hope you´re fine, I´m sorry if this idea was posted before (I made a search but I haven´t find anything related). So, Having the possibility of stacking notebooks would be an interesting way to order notebooks that correspond to the same
Writing on sketch cards is bugged when zoomed in
When zoomed in, it writes a noticeable distance above or to the side of where you're actually trying to write. The further you're zoomed in, the more noticeable it is. Zooming is also entirely absent on the desktop version.
Swipe between notes on iPhone
It'd be convenient if I could move from one note to the next in a notebook simply by swiping left to right.
Sales IQ chat is not working in signed android apk
I have integrated ZOHO sales IQ support chat and i have followed each step and its working fine in my development build but when i create signed APK for it. Chat does not work in it and showing awaiting for detail. I previously asked the same query but
COQL order by COUNT not working
Dear community, I am trying to get a list of deal amounts per planner working on it and sorted to get see who has the least amount of deals. For some reason, I am unable to use sort by in combination with a COUNT. My original code was: query = "select
I want to duplicate a report and name it something else
Hi, I have created a report, and now want to reproduce it and call it something else. so that I will end up with TWO separate reports with different titles. Please tell me how do I copy / reproduce a report please
Zoho CRM: Sales Rep Professional Certification Program on Coursera
We are happy to share that we have published the Zoho Sales Representative Professional Certificate in partnership with Coursera, a leading platform for online learning and career development that offers access to courses and degrees from leading universities
Next Page