{"id":290,"date":"2014-03-03T14:51:13","date_gmt":"2014-03-03T21:51:13","guid":{"rendered":"http:\/\/constantinekrick.com\/?p=290"},"modified":"2014-03-04T21:49:57","modified_gmt":"2014-03-05T04:49:57","slug":"integrate-servicenow-with-jquery","status":"publish","type":"post","link":"http:\/\/constantinekrick.com\/?p=290","title":{"rendered":"Integrate ServiceNow with jQuery"},"content":{"rendered":"<p>Integrating ServiceNow and jQuery can be very intimidating. This post will go through the process of creating a ServiceNow page that integrates with\u00a0<a href=\"http:\/\/jquery.com\/\" target=\"_blank\">jQuery<\/a>\u00a0and the\u00a0<a href=\"http:\/\/jqueryui.com\/\" target=\"_blank\">jQuery UI<\/a>\u00a0libraries. \u00a0The ServiceNow page will be displayed through a <a href=\"http:\/\/wiki.servicenow.com\/index.php?title=GlideDialogWindow_API_Reference\" target=\"_blank\">GlideDialogWindow<\/a>\u00a0for a very clean and integrated effect that shows a window with the <a href=\"http:\/\/jqueryui.com\/accordion\/\">jQueryUI accordion<\/a>\u00a0plugin.<\/p>\n<p><strong>Screenshot of the completed demo:<br \/>\n<a href=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/IncidentPageGlideDialogWindowExampleStart.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-300\" alt=\"IncidentPageGlideDialogWindowExampleStart\" src=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/IncidentPageGlideDialogWindowExampleStart.jpg\" width=\"860\" height=\"548\" srcset=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/IncidentPageGlideDialogWindowExampleStart.jpg 860w, http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/IncidentPageGlideDialogWindowExampleStart-300x191.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/strong><br \/>\n<!--more--><\/p>\n<h2>Step 1 : Uploading the jQuery and jQuery UI files to ServiceNow<\/h2>\n<p>ServiceNow will allow the <strong>&lt;script src=&#8221;&#8230;&#8221;&gt;<\/strong> tag to be used on a standalone page; <em><span style=\"text-decoration: underline;\"><strong>however<\/strong><\/span><\/em>, since we will be using this inside a Glide Dialog Window <em>the source code of jQuery and jQueryUI must be uploaded to the UI Scripts library.<\/em><\/p>\n<p>When working in Jelly, ServiceNow will allow us to call the scripts through the tag <strong>&lt;g:include_script&gt;. \u00a0<\/strong>This tag will be furthered explained in step 2.<\/p>\n<ol>\n<li>To upload the scripts, navigate to <strong>UI Scripts<br \/>\n<strong><a href=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/Step1UI-Scripts-Part1.jpg\"><img decoding=\"async\" loading=\"lazy\" alt=\"Step1UI Scripts Part1\" src=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/Step1UI-Scripts-Part1.jpg\" width=\"756\" height=\"157\" \/><\/a><\/strong><br \/>\n<\/strong><\/li>\n<li>Copy and past the source code of both <strong>jQuery<\/strong> and <strong>jQueryUI<\/strong> files into ServiceNow. Both files can be downloaded from\u00a0<a href=\"http:\/\/jqueryui.com\/download\/\" target=\"_blank\">http:\/\/jqueryui.com\/download\/<\/a>. \u00a0(It is recommended to use the jQuery min files as they are smaller and will load faster; however, I have used the easier to read forms in this demo in order to increase readability).<br \/>\n<a href=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/Step1UI-Scripts-UploadJquery.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-305\" alt=\"Step1UI Scripts UploadJquery\" src=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/Step1UI-Scripts-UploadJquery.jpg\" width=\"736\" height=\"454\" srcset=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/Step1UI-Scripts-UploadJquery.jpg 736w, http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/Step1UI-Scripts-UploadJquery-300x185.jpg 300w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/a><\/li>\n<\/ol>\n<h2>Step 2 : Creating the UI Page<\/h2>\n<p>The UI page is the most complex part of this setup as there are two important parts&#8230; the<\/p>\n<p><strong>&lt;g:include_script src=&#8221;jQueryFILE.jsdbx&#8221;&gt;<\/strong><br \/>\nand the use of &#8230;<br \/>\n<strong>jQuery.noConflict(true);<\/strong><\/p>\n<p><strong><\/strong><em>* Tyler Jones wrote a great article on the <a href=\"http:\/\/jylertones.com\/blog\/2013\/05\/the-right-way-to-use-jquery-with-servicenow\/\">Right Way to Use jQuery With ServiceNow<\/a>\u00a0detailing the two commands above.\u00a0<\/em><\/p>\n<p>Here is the UI Page code. Notice that instead of using <strong>$ or $j, we are creating our own context for our version of jQuery in the variable $j_custom to ensure we do not conflict with any version&#8217;s of jQuery that ServiceNow is using.\u00a0<\/strong><\/p>\n<p>Also, the jQueryUI depends on a CSS style sheet. I am using the one from the <a href=\"https:\/\/developers.google.com\/speed\/libraries\/devguide\">Google APIs.<\/a><\/p>\n<p>UI Page Name =\u00a0<strong>jqueryUIpage<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\" ?&gt;\r\n&lt;g:include_script src=\"jQuery1_10_2.jsdbx\"\/&gt;\r\n&lt;g:include_script src=\"jQuery-ui-1_10_4_custom_min.jsdbx\"\/&gt;\r\n&lt;link href=\"\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.10.4\/themes\/smoothness\/jquery-ui.css\" rel=\"stylesheet\" \/&gt;\r\n\r\n&lt;script type=\"text\/javascript\"\/&gt;\r\nvar $j_custom = jQuery.noConflict(true);\r\n  $j_custom(function() {\r\n    $j_custom(\"#accordion\").accordion();\r\n  });\r\n&lt;\/script&gt;\r\n\r\n&lt;div id=\"accordion\"&gt;\r\n&lt;h3&gt;What is needed for this example?&lt;\/h3&gt;\r\n&lt;div&gt;\r\n&lt;ul&gt;\r\n   &lt;li&gt;ServiceNow - With an understanding of UI Pages, UI Macros, UI Scripts, and the Glide Dialog Window&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n&lt;ul&gt;\r\n  &lt;li&gt;jQuery&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n&lt;ul&gt;\r\n  &lt;li&gt;jQuery UI&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n&lt;\/div&gt;\r\n&lt;h3&gt;Can I use it in ServiceNow?&lt;\/h3&gt;\r\n&lt;div&gt;\r\nAbsolutely! Make sure to use the jQuery noConflict(true) to ensure that this works.\r\n&lt;\/div&gt;<\/pre>\n<h2>Step 3: Create the UI Macro<\/h2>\n<p>The UI macro will allow an icon to be shown next to a field in ServiceNow. This is a great way of ensuring that an Incident form does not become cluttered with too many fields.<\/p>\n<ol>\n<li>Upload an image to the images gallery that is 16&#215;16 pixels. This example will use the icon triangle.jpgx \u00a0<a href=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/triangle.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-326 alignnone\" alt=\"triangle\" src=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2014\/03\/triangle.jpg\" width=\"16\" height=\"16\" \/><\/a><\/li>\n<li>The UI Macro will launch a pop up window inside the webpage. More can be read about the <a href=\"http:\/\/wiki.servicenow.com\/index.php?title=GlideDialogWindow_API_Reference\">GlideDialogWindow here<\/a>.<\/li>\n<li>Create the UI Macro.<br \/>\nName =\u00a0<strong><strong>jqueryMacro<\/strong><\/strong><\/li>\n<\/ol>\n<pre>&lt;!--?xml version=\"1.0\" encoding=\"utf-8\" ?--&gt;\r\n&lt;g:reference_decoration id=\"jqueryMacro\" field=\"${ref}\" onClick=\"invokejQuery('${ref}');\" title=\"Invoke Jquery Example\" image=\"triangle.jpgx\"\/&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\nfunction invokejQuery(){\r\nvar box = new GlideDialogWindow('jqueryUIpage');\r\nbox.setTitle('jQuery');\r\nbox.setSize(400,400);\r\nbox.render();\r\n}\r\n&lt;\/script&gt;<\/pre>\n<ul>\n<li>\u00a0Go the incident form,\u00a0<strong>Right click on the caller field, <\/strong>select<strong> Personalize Dictionary,\u00a0<\/strong>and add the following :<br \/>\n<strong><br \/>\nfield_decorations=jqueryMacro<br \/>\n<\/strong>*Seperate other attributes with a comma. If you have more than one field decoration, separate each decoration with a comma. \u00a0More can be read about <a href=\"http:\/\/wiki.servicenow.com\/index.php?title=Dictionary_Attributes\">Dictionary Attributes here.<\/a>\u00a0Last note, the attribute\u00a0ref_contributions can reference only one UI Macro, where as field_decoration can reference multiple UI Macros.<\/li>\n<\/ul>\n<h2>Conclusion:<\/h2>\n<p>I have not seen a lot of documentation or usage of jQuery inside ServiceNow. With that said, use at your own risk as the jQuery UI libary does not have the option of the jQuery noConflict. If ServiceNow decides to use jQueryUI, the code may need to be updated to reflect this <a href=\"http:\/\/stackoverflow.com\/questions\/4214551\/using-different-versions-of-jquery-and-jqueryui-together\">Stack Overflow question.\u00a0<\/a><\/p>\n<p>Please let me know of any questions or thoughts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Integrating ServiceNow and jQuery can be very intimidating. This post will go through the process of creating a ServiceNow page that integrates with\u00a0jQuery\u00a0and the\u00a0jQuery UI\u00a0libraries. \u00a0The ServiceNow page will be displayed through a GlideDialogWindow\u00a0for a very clean and integrated effect &hellip; <a href=\"http:\/\/constantinekrick.com\/?p=290\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[7],"tags":[9,8,11],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1x8ho-4G","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/posts\/290"}],"collection":[{"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=290"}],"version-history":[{"count":39,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/posts\/290\/revisions"}],"predecessor-version":[{"id":337,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/posts\/290\/revisions\/337"}],"wp:attachment":[{"href":"http:\/\/constantinekrick.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=290"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}