Changing the URL type field display value

I was recently given a requirement to change the display text of the URL field in ServiceNow to be shorter and more user friendly. Here is how I implemented the solution. This takes into account the different ways you can view a record, either within the normal frame view, without the frame as well as the grid view (for list v3). I Hope you find this useful!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function onCondition() {
  g_form.setSectionDisplay('sl1_event', true);
  try {
    var doc;
    var iframe = top.document.getElementById('gsft_main'); //main iframe
    var listIframe = iframe ? iframe.contentWindow.document.querySelector('[name=gsft_list_form_pane]') : null; //split view iframe
    //listIframe is null if iframe is null (when open record outside of frame, ie. not within nav_to) OR can not be determined by the selector above (for when the record is opened in regular form view, no split view)
    if (listIframe == null)
      doc = iframe ? iframe.contentWindow.document : top.document;
    else
      doc = listIframe.contentWindow.document; //listIframe exists when record is opened in split view, set doc to listIframe.contentWindow.document

    var element = doc.getElementById('incident.u_sciencelogic_link_link');
    if (element)
      element.innerHTML = 'Event Current Status'; //set text of URL
  } catch (ex) {
    console.log(ex);
  }
}
5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments