document.getElementsByTagName is not working in Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 10:39 PM
Hi,
document.getElementsByTagName is not working in service portal. is there any replacement of it ??
Code which we are using:
var icons = document.getElementsByTagName('a');
for (i = 0; i < icons.length; i++) {
if (icons[i].id == 'catalog_super_diamond_anchor') {
icons[i].onclick = null;
}
}
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 10:42 PM
Document is not supported by the Service Portal:
As for a workaround I have seen 'this.document' being suggested in the community. However that did not work for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 11:01 PM
Script will look like this:
var icons = this.document.getElementsByTagName('a');
for (i = 0; i < icons.length; i++) {
if (icons[i].id == 'catalog_super_diamond_anchor') {
icons[i].onclick = null;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 10:54 PM
Hello Rohit,
The catalog client script ui type should be set to ALL.
and you have to use this.document and it will work. I have modified the script. Check this.
var icons = this.document.getElementsByTagName('a');
for (i = 0; i < icons.length; i++) {
alert("Entered while loop");
if (icons[i].getAttribute("id") == 'catalog_super_diamond_anchor') {
alert("Entered if condition");
icons[i].onclick = null;
}
}
Kindly mark the comment as a correct answer and also helpful if this solves the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 10:57 PM
Can you try this and check once
1) Set Isolate Script field on your client script as False
- This field is not on form but from list you can set it to false
- by default it is true
2) Update script as below
var icons = this.document.getElementsByTagName('a');
for (i = 0; i < icons.length; i++) {
if (icons[i].id == 'catalog_super_diamond_anchor') {
icons[i].onclick = null;
}
}
I was able to use this.document.getElementsByClassName() in portal view and it worked fine for me.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader