<!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" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.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> |
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);} } |
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); } |
Writer is a powerful online word processor, designed for collaborative work.