How to call UI script in client script

sunnysunny
Kilo Contributor

I created a simple ui script, as mentioned below. How can I call this from client script?

function displaytitle()

{

  var a= g_form.getValue('number');

  var b= g_form.getValue('short_description');

  if(a && b)

{

  top.document.title= a +'-'+ b;

}

  else

  {

  alert('hello');

  }

}

15 REPLIES 15

balaji_charapal
Kilo Guru

Hi sunny,



you can refer below wiki link


UI Scripts - ServiceNow Wiki


Harneet Sital
Mega Sage
Mega Sage

Hi Sunny,



You can mark a UI script as Global to make it available on any form in the system.


After you create this global UI script, you can call the function from any client script or UI policy you write.


In your case, just make the UI script as global and call displaytitle() in all of the client scripts.



Refer global UI sciprts for more :


http://wiki.servicenow.com/index.php?title=UI_Scripts#gsc.tab=0


amlanpal
Kilo Sage

Hi Sunny,



You can call the UI Script like below. Lets say your UI Script name is myUIScript.



var validateFields = new myUIScript();


validateFields.getDateFields(g_form);



I hope this helps.Please mark correct/helpful based on impact



balaji_charapal
Kilo Guru

Hi Sunny,



you can also See Extensions to Jelly Syntax - ServiceNow Wiki Section 9.