The CreatorCon Call for Content is officially open! Get started here.

document.getElementsByTagName is not working in Portal

Rohit Agarwal
Mega Expert

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;
}
}

12 REPLIES 12

Willem
Giga Sage
Giga Sage

Document is not supported by the Service Portal:

https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/build/service-portal/concept/un...

 

As for a workaround I have seen 'this.document' being suggested in the community. However that did not work for me.

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;
    }
}

asifnoor
Kilo Patron

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.

Ankur Bawiskar
Tera Patron
Tera Patron

@Rohit Agarwal 

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

find_real_file.png

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader