<script custom-tag="" type="application/ld+json">{"@context":"https://schema.org","@type":"TechArticle","headline":"Javascript TypeError created when UI Pages are used as catalog item variables","image":"http://support.servicenow.com/29f1d2661baf6010cafa53d8624bcb43.iix","author":{"name":"ServiceNow Support","url":"http://support.servicenow.com/now"},"keywords":"ServiceNow, NowSupport public Knowledge Base articles, Known Error,KB0547297,Javascript_TypeError, UI_Pages, catalog_item_variables, service_catalog","wordcount":"408","publisher":"ServiceNow","url":"https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0547297","datePublished":"2015-02-17","dateCreated":"2015-02-17","dateModified":"2024-04-07","description":"<h2>Javascript TypeError created when UI Pages are used as catalog item variables</h2><br/><div style=\"overflow-x:auto\"><h2>Description</h2><div><p>* DESCRIPTION<br />-------------<br /><br />UI Pages","articleBody":"<h2>Javascript TypeError created when UI Pages are used as catalog item variables</h2><br/><div style=\"overflow-x:auto\"><h2>Description</h2><div><p>* DESCRIPTION<br />-------------<br /><br />UI Pages included in a Catalog Item as a variable result in the next error (browser javascript console) when trying to add the item to the cart:<br /><br /> Uncaught TypeError: Cannot read property 'innerText' of null <br /><br />* ANALYSYS<br />----------<br /><br />The error is thrown in "js_includes_doctype.jsx", line "var text = label.firstChild.innerText":<br /><br />| getLabelOf: function (fieldName) {<br />| var fieldid = this.tableName + '.' + fieldName;<br />| fieldid = this.resolveNameMap(fieldName);<br />| var label = gel('label_' + fieldid);<br />| if (label) {<br />| var text = label.firstChild.innerText;<br />| if (!text)<br />| text = label.firstChild.textContent;<br />| return text;<br />| }<br />| return null;<br />| },<br /><br />Indeed the label does not have a firstChild for UI Page variables.<br />The call stack shows that this function is called when the variable is set mandatory:<br /><br />| Class.create.getLabelOf (js_includes_doctype.jsx?v=08-27-2014_1022&lp=Wed_Sep_17_06_21_51_PDT_2014&c=5_46:8570)<br />| Class.create.mandatoryCheck (js_includes_doctype.jsx?v=08-27-2014_1022&lp=Wed_Sep_17_06_21_51_PDT_2014&c=5_46:8522)<br />| Class.create.catalogOnSubmit (js_includes_doctype.jsx?v=08-27-2014_1022&lp=Wed_Sep_17_06_21_51_PDT_2014&c=5_46:8844)<br />| addToCart (com.glideapp.servicecatalog_cat_item_view.do?v=1&s…m_id=8f9a3d1681394d00d799616040d45dc1&syspar…:406)<br />| onclick (com.glideapp.servicecatalog_cat_item_view.do?v=1&s…m_id=8f9a3d1681394d00d799616040d45dc1&syspar…:384)<br /><br />Probably we would need to skip the mandatoryCheck for this kind of variables, or in case we decide to make the check, make sure that firstChild is not null before trying to access it.<br /><br />* WORKAROUND<br />------------<br /><br />Set the variable "Mandatory: no"<br /><br />* NOTES<br />-------<br /><br />There is a similar bug with UI Page and Macros not processing in service catalog when included as a variable: PRB580457 <br />But that one is when "rendering" the variable.</p></div><h2>Steps to Reproduce</h2><div> <p></p><p>Reproduced in Eureka Patch 4 Hot Fix 1<br /><br />1) Go to System UI > UI Pages and crate a page containing the next in the HTML field:<br /><br /> <?xml version="1.0" encoding="utf-8" ?><br /> <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"><br /> <div>Dummy text</div><br /> </j:jelly><br /><br />2) Create a Catalog Item<br />3) Add a variable to the item with the next values:<br />~ Type: UI Page<br />~ Mandatory: yes<br />~ UI Page: <select here the UI Page created before><br />4) Back in the form of the Catalog Item click "Try It". Observe the text "Dummy text" in the cart item.<br />5) Click "Order Now"<br /><br />~ Expected behaviour: the form moves to the next page (checkout)<br />~ Observed behaviour: the form does not move on and an error is observed in the browser javascript console: <br /><br /> Uncaught TypeError: Cannot read property 'innerText' of null</p></div><h2>Workaround</h2><div>There is no workaround for this Known Error at this time.</div><div><br /><strong>Related Problem: PRB609223</strong></div></div>"}</script>