UI Script and DOM

Andrew Pishchul
Giga Expert

I'm trying to test a simple UI Script, but feel kind of lost - it's not working.. The idea is very simple - I want to make "Homepage" menu item under Self-Service red. I know the element id, but script is not working... I even added addLoadEvent function, no success... any ideas?

Screen Shot 2015-12-03 at 10.50.54 PM.png

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Andrew,



The following global UI script does the trick in Geneva



try {


  getTopWindow().document.getElementById("4aeebcd20a0a0b9a00572ae3ad68b072").style.backgroundColor = 'red';


}


catch(e){


}



Thanks,


Berny


View solution in original post

23 REPLIES 23

Hi Berny,


Its a great tweak. I was trying to use "Window.document" but it was unable to identify document object, but getTopWindow() method works fantastically.



Regards,


Swarnadeep Nandy


Thanks swarnadeepnandy for taking the time to comment that this solution worked for you. I'm really glad it was helpful!



Just keep in mind to be cautious of future releases as this type of scripting could break if the html structure could change through release/patches of ServiceNow.



Thanks,


Berny


Hi Berny,



getTopWindow() is working fine when the form is opened in a new window, but when it is opened inside the navigation pane iframe, it is notworking.
PFB the screenshot for the same


find_real_file.png


Any workaround for this?
Is it something that getTopWindow() not able to take the id as it is inside the iframe?





Thanks & Regards,


Swarnadeep Nandy