UI

scripts in Service-now are one of those things that can be very useful but aren’t very well known.  They allow you to do a lot of client-side javascript manipulation of places in the form that you might not otherwise be able to get to.  One good example of this is setting the browser window title dynamically based off of the content of records being displayed.



By default, Service-now displays the same window title information all of the time no matter what you’re looking at within the application.  This isn’t normally an issue, but it can be frustrating if, like me, you work with multiple browser tabs open that all have something to do with Service-now.

You might just prefer to look at a different title every now and then :).  In my client’s case, they wanted to change the window title dynamically when they opened up a task ticket. They wanted to show the Number and Short description of the task being displayed. Otherwise, they wanted to show the default title. We accomplished this with the addition of a simple global UI script as outlined in the steps below…

1Navigate to ‘System UI -> UI scripts’ and create a new UI script

2Name the script ‘DynamicWindowTitle’ and check the ‘Global’ checkbox

3Use the following script in your UI script

addLoadEvent(setTitle);
function setTitle(){
   try{
      var num = g_form.getValue('number');
      var sd = g_form.getValue('short_description');
      var nme = g_form.getValue('name');

      //Check if viewing a KB article
      if($('kb_view')){
         num = $('permalink').href.split('sysparm_article=')[1];
         sd = $$('.kb_article_header_short_description')[0].innerHTML;
      }
   }catch(e){
   //alert('Error getting title info.');
}
   if(num && sd){
      top.document.title = num + ' - ' + sd;
   }
   else if(nme){
      top.document.title = nme;
   }
   else{
      top.document.title='Service-now.com - IT Service Management Suite';
   }
}