The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reusing Client Scripts without Global UI Scripts

Makosko
Giga Expert

Hello Gurus,

is there a way to embed a UI script into a local client script ? could be on a form or as part of wizard or even catalog item... I do NOT want to use a global UI script, which would be loaded on every single page...

Cheers

Maros

1 ACCEPTED SOLUTION

chandan_nagbans
Giga Expert

Hi Maros,



For doing that, you have to follow below steps:



1. Create a UI Macro like below:



        <?xml version="1.0" encoding="utf-8" ?>  


        <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">  


              <g2:evaluate var="jvar_stamp">  


            var gr = new GlideRecord('sys_ui_script');  


            gr.orderByDesc('sys_updated_on');  


            gr.query();  


            gr.next();  


            gr.getValue('sys_updated_on');  


              </g2:evaluate>  


              <g:requires name="<UI SCRIPT NAME>.jsdbx" params="cache=$[jvar_stamp]" />  


        </j:jelly>




2. Create a formatter specific to your form & include that in your form view.



You are ready to go now.



Source: UI Scripts - ServiceNow Wiki


View solution in original post

3 REPLIES 3

ghaing
Giga Expert

Hi,


here some best practices. It could help you:



http://jylertones.com/blog/2013/05/the-right-way-to-use-jquery-with-servicenow/



Regards,


chandan_nagbans
Giga Expert

Hi Maros,



For doing that, you have to follow below steps:



1. Create a UI Macro like below:



        <?xml version="1.0" encoding="utf-8" ?>  


        <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">  


              <g2:evaluate var="jvar_stamp">  


            var gr = new GlideRecord('sys_ui_script');  


            gr.orderByDesc('sys_updated_on');  


            gr.query();  


            gr.next();  


            gr.getValue('sys_updated_on');  


              </g2:evaluate>  


              <g:requires name="<UI SCRIPT NAME>.jsdbx" params="cache=$[jvar_stamp]" />  


        </j:jelly>




2. Create a formatter specific to your form & include that in your form view.



You are ready to go now.



Source: UI Scripts - ServiceNow Wiki


I suppose this approach will work with Catalog Items if i create a new variable of Macro type? I`ll try it out tmrw and let you know.. thanks a lot for your tip !