<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 &#39;innerText&#39; of null <br /><br />* ANALYSYS<br />----------<br /><br />The error is thrown in &#34;js_includes_doctype.jsx&#34;, line &#34;var text &#61; label.firstChild.innerText&#34;:<br /><br />| getLabelOf: function (fieldName) {<br />| var fieldid &#61; this.tableName &#43; &#39;.&#39; &#43; fieldName;<br />| fieldid &#61; this.resolveNameMap(fieldName);<br />| var label &#61; gel(&#39;label_&#39; &#43; fieldid);<br />| if (label) {<br />| var text &#61; label.firstChild.innerText;<br />| if (!text)<br />| text &#61; 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&#61;08-27-2014_1022&amp;lp&#61;Wed_Sep_17_06_21_51_PDT_2014&amp;c&#61;5_46:8570)<br />| Class.create.mandatoryCheck (js_includes_doctype.jsx?v&#61;08-27-2014_1022&amp;lp&#61;Wed_Sep_17_06_21_51_PDT_2014&amp;c&#61;5_46:8522)<br />| Class.create.catalogOnSubmit (js_includes_doctype.jsx?v&#61;08-27-2014_1022&amp;lp&#61;Wed_Sep_17_06_21_51_PDT_2014&amp;c&#61;5_46:8844)<br />| addToCart (com.glideapp.servicecatalog_cat_item_view.do?v&#61;1&amp;s…m_id&#61;8f9a3d1681394d00d799616040d45dc1&amp;syspar…:406)<br />| onclick (com.glideapp.servicecatalog_cat_item_view.do?v&#61;1&amp;s…m_id&#61;8f9a3d1681394d00d799616040d45dc1&amp;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 &#34;Mandatory: no&#34;<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 &#34;rendering&#34; 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 &gt; UI Pages and crate a page containing the next in the HTML field:<br /><br /> &lt;?xml version&#61;&#34;1.0&#34; encoding&#61;&#34;utf-8&#34; ?&gt;<br /> &lt;j:jelly trim&#61;&#34;false&#34; xmlns:j&#61;&#34;jelly:core&#34; xmlns:g&#61;&#34;glide&#34; xmlns:j2&#61;&#34;null&#34; xmlns:g2&#61;&#34;null&#34;&gt;<br /> &lt;div&gt;Dummy text&lt;/div&gt;<br /> &lt;/j:jelly&gt;<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: &lt;select here the UI Page created before&gt;<br />4) Back in the form of the Catalog Item click &#34;Try It&#34;. Observe the text &#34;Dummy text&#34; in the cart item.<br />5) Click &#34;Order Now&#34;<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 &#39;innerText&#39; 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>
  Loading...