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
Support for Transparent, Shadowless Panels in Zoho Creator Pages
Hi Zoho Creator Team, Hope you're doing well. We would like to request more design flexibility in Zoho Creator, specifically the ability to create panels with no background, border, or shadow. Use Case: In our app, we’re designing a dashboard that uses
Looping issues
Can someone please explain why this doesn't infinitely loop, but the second one does? How can I get around this? This one loops ⬇️
Automation#33: Automate Splitting Names for Existing Contact Records
An organized directory – who doesn't love one? Previously, we explored how to split contact names into First Name and Last Name for new contacts in Zoho Desk. But what about existing contacts already in your database? This week, we bring you a custom
Automation#31: Automate Splitting Names for New Contact Records
Hello Everyone, This week, we present to you a custom function, which allows you to split the first and last names from the user's email ID based on the separator used in the ID. Having grown into a large firm, Zylker Techfix aims to optimize its processes,
Shopify sales orders creating a new account in Zoho
Hi all, I am having a slight issue with the shopify integration. Whenever a customer purchases from the store, shopify automatically creates a sales order in inventory. The issue is that it creates a new account for the customer's name instead of attaching
Bar left hand side iphone app
Hi, using the Zoho Mail app on my iphone and I can see that some emails in the list have a thin, pale bar at the left but I have no idea what this signifies? See image. Any idea? Thanks
automatic time stamp and field age
Hi, I am trying to note the time when a certain field is updated in Zoho CRM. I've been able to create a rule that would trigger the respective field update. However, for the field where I'd like the current time stamp to be automatically recorded, I'm not being able to add a dynamically generated time. I can only add some static text. Is there a way to dynamically generate time stamps? Subsequently, I'd like to know how to show the age of the field once I've generated the time stamp (for e.g.2 months
NOW Zoho Creator still cannot bulk download Image or File Upload Field
The filedownloader has been deprecated for 5 years. Until now, we still cannot have a replacement tool. How can we bulk download the file that we uploaded to Zoho Creator. Previously, it was so simple to bulk download all those files. But now failed to
Zoho Creator delete validation seems like does not support <br> html code
Validation Workflow in Create or Edit, We can use this styling code eg: <br>, <b>, <u> Those very simple code in those validation (in Create or Edit) But, for Validation (In Delete) Zoho Creator seems like does not support it. The alert task just shown
How to unvoid sales order ?
Helo, We need to make a credit not from a voided invoice, which is linked to a voided sale order. I can't find a way to unvoid a sale order. There only a way to convert it to a Purchase order instead... The invoice can't be send back to draft because of the voided sale order. From a accountancy point of view, and treacability, we can't make a standalone credit note. What is the usual procedure? Thanks
Introducing body parameter for invokeUrl
Hello everyone, We’re excited to announce that the invokeUrl Deluge task now supports body payloads and allows you to send data with all HTTP methods. Previously, GET and DELETE requests couldn’t include a body payload, and this limited your API interactions.
Zoho Sites Vs Zoho LandingPage
Hello everyone, I'm currently exploring the various tools offered by Zoho and have a couple of questions: What is the difference between Zoho Sites and Zoho LandingPages? I'm trying to understand their primary use cases and how they differ from each other.
Managing external users for Cliq when organization is a Zoho One User
Hi All, I am having a problem and would like to know if anyone else has experienced the same and more than anything if you were able to resolve the problem. My problem is that I set up Cliq and finally got all users on board and using the chat in place of email. Most of our users are external subcontracted teachers that we need to from time to time coordinate things with. Well, once Cliq became a part of Zoho One, I worried that I would then have to add all of the external users to Zoho One. Of course
[Product update] Teamwork Integration with Zoho Analytics
Hello Customers, As part of our ongoing efforts to enhance integrations, we are upgrading our Teamwork integration with Zoho Analytics from the V1 to V3 version of the People module. We’re also pleased to inform you that this update brings new field additions,
Apply Workspace First Day of Month Setting to User Filter Date Picker
I've noticed that the user date picker filter always has the first day of the week as Sunday, even when Monday is selected as the Workspace default. I would like to raise a feature request to apply the Workspace default to user date pickers. Thanks
Highlight a candidate who is "off limits"
Hello: Is there a way to highlight a candidate who is "off limits"? I would like to have the ability to make certain candidate and / or Client records highlighted in RED or something like that. This would be used for example when we may have placed a candidate somewhere and we want everyone in our company to quickly and easily see that they are off limits. The same would apply when we want to put a client or former client off limits so no one recruits out of there. How can this be done? Cheers,
Count the number of subform records associated with parent record
Hello! I have a main form which contains all the details of a particular Issue, and then a subform where we can enter some information about each client who is affected by that Issue. What I want to do is have a field in the main form contain a count of the number of clients who have been affected, and automatically update when a new client's information is entered in the subform. Essentially, just a count of the records in the subform that are associated with that parent record. I've tried variations
RingCentral Intergration Fax
Hello Zoho Community , I recently intergrated with ring central with zoho crm. Ring central is a fully loaded buisness VOIP and Fax system , however I think there should be a button in Zoho to allow users to fax out the same way users are able to fax
[Product update] Instagram Profiles Integration with Zoho Analytics
Dear Customers, We want to inform you about an update affecting the Instagram Profile integration with Zoho Analytics. Meta is deprecating the "Impressions" and "Plays" metrics as per their announcement in this change-log document. To ensure uninterrupted
how to prevent some user to choose the stage in deal module when creating a deal record?
I want to prevent some users to choose a deal stage when creating a deal record I want some users to follow the pipeline from top to bottom. can I do that? because it seems I can't hide this field . is there any workaround for this? can I hide it using
Quotes: Export to PDF and attach using API
Hello, I would like to automate the following: - create a Quote for an account - export that quote to PDF - upload the PDF back into ZohoCRM, as an attachment for that Quote using API methods. Is this possible, has anybody done this before? Thank yo
Zoho CRM Contact Form style in website
Hello, I am trying to embed the Contact Form from Zoho CRM into our existing WordPress website to replace our current contact form. The look on the website is not similar to the 'Preview' when I am setting up the form in the CRM, and I have limited html
Data Sync
Hi, is there any scope for live data synchronization with CRM and Analytics, especially as TV channels for motivator is unable to provide charts, dashboards within Analytics seems the obvious solution?
I have integrated WhatsApp but it in vissible to sent message to customers
I have integrated WhatsApp but it in vissible to sent message to customers.
Embedding SalesIQ in Zoho Creator within a (Internal) Widget - Not customizable
I've been trying to integrate SalesIQ within an application in Zoho Creator. And since <script> tags can't be rendered within the HTML snippet, I've created a separate widget which is hosted internally (through packed .zip file) and added SalesIQ through
Zoho Campaigns - how to have distinct Lead and Contact segments?
Hi, I have been using Zoho Campaigns for quite a while now. What is not clear to me is how to have distinct segments for Leads and Contacts. I tried and used filters to do the trick, but that doesn't always work as I expect. For instance, converted Leads
OAuth Error - {"error":"invalid_code"}
curl -v --ipv4 -X GET \ --url 'https://accounts.zoho.com/oauth/v2/auth?response_type=code&client_id=[CLIENT_ID]&scope=AaaServer.profile.Read&redirect_uri=https://my-real-domain.com/zohocallback.xhtml&prompt=consent&access_type=offline' RESPONSE Location:
Zoho Campaigns Pop Up not scaling properly on phone browser
The pop up for the sign up for my mailing list works fine on my browser on PC, but on phone, it only shows half of the pop up. How do I fix this?
📣📣 Zoho Bookings - Feature Roadmap 2024
Hi Everyone, Thank you for all the support you have been showing Zoho Bookings. We had a fabulous 2023, with a bunch of new features and over 60K new users. In 2024, our prime focus will be on user experience, and we have a few vital features coming in
Cannot add Outlook Calendar to Zoho Bookings
Hello, When I try to add my Outlook Calendar to Zoho Bookings I get almost to the end, including accepting the permissions and authorising the Office 365 account then I get the error message "Something's not right on our side. Sorry about that. Please
booking link that expires
I have a suggestion that is crucial. When i send booking URL to clients they keep the link and they book appointment whenever they want multiple times. You should give us the Booking URL feature. We should be able to send it and the user can use it only
Bookings - How do you select more than 1 service?
Hello - I'm setting up a client with CRM and Bookings. She is a beautician that needs to have people book more than 1 service at time. Some services are add-on and she wants to collect a deposit but not the full payment. How do we allow the clients to book more than 1 service at a time? Can the system take partial payments?
Introducing ICR in Zoho CRM: Transform your printed text into digital data
From writing on papyrus in the ancient times to creating a humble record in your CRM, the world may have evolved with how it used to record data, but data entry as such has not been simplified. It is still a repetitive and arduous chore on which businesses
Auto-Generate & Update Asset Serial Numbers using a custom function (Assets Module)
Hello Team, I’ve been working on a script to automate one of our processes in Zoho FSM, and the core functionality has been successfully implemented. However, I’m encountering an issue related to serial number allocation, which is not working as expected.
Linking Reports and Projects to CRM Portal
Is there a way to link reports and projects to a CRM portals?
How to filter deals for anything not yet delivered
Hello I want to be able to filter my deals for anything where the Sales Order is not delivered. I'm stuck because I want to include deals with and without Sales Orders, and just exclude ones with an associated Sales Order which is stage Delivered Does
Currency fields and decimal places in CRM email templates
Hi, How do I get more than the standard 2 decimal places showing in a Currency field, on an email template? In the Layout for my Currency field, it is set to 6 decimal places. I want to show up to 6 places in the email template (unrounded). See attached
Package Dimensions
Packages need to have dimensions that are sent to carriers in addition to just the weight. Without the package dimensions being transmitted to carriers, the correct dimensional weight is not calculated for the label price, which results in corrections
Zoho One for Multiple Organisation under a Parent Company
Dear Zoho One, We are a two companies running different business (service and sales) in Malaysia, with our parent HQ in Germany, and we have multiple sister companies scattered across the region of Asia. Currently, our malaysia branch is using Zoho CRM and are in the process of upgrading our accounting system with Zoho One. However, there is one huge problem, and that is Zoho Apps does not allow us to run multiple organisations with a single subscription. This is our only deal breaker at the moment/
Track All Emails from Company Domain
For our business model, it's almost impossible to keep track of all emails sent to clients, under the way ZohoCRM currently tracks emails to customer records via the user account only. We'd like to see a way of tracking emails via domain only, separate
Next Page