Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Write script on list view

xiaix
Tera Guru

Trying to write a Client Script (onLoad) for a table list view is not working.   How can this be done?

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi David,



onLoad client scripts only run when the form is loaded, not in a list. The only type of client script that applies to a list is onCellEdit.



http://wiki.servicenow.com/index.php?title=Client_Scripts


View solution in original post

13 REPLIES 13

btw... when you were walking down to enter that long line at the Harry Potter ride at Universal, I was the guy who interrupted your attention from you looking at your phone by saying, "Hey, Chuck".   You briefly looked up and gave a smile.   I was going to let you take my spot!   lol


Hi David,



Thanks for the memory at K17. I apologize if I seemed inattentive. I recall having several conversations on the phone at the same time with people who were trying to meetup.   I wish I had a chance to meet and talk to everyone in person. I appreciate the thought of giving up your spot in line.



Regarding the list calculations and layout - I'd report it through HI as a bug or enhancement. If we're doing sums or averages, that implies numbers which are usually right justified. Seems like an oversight on my part.



I invite you to open an enhancement request! Our product managers DO listen.


Enhancement requests: Tell us how you would improve the ServiceNow product


No worries   Thanks for the advice!


xiaix
Tera Guru

(function() {


      setTimeout(function(){


              var aTags_ = document.getElementsByTagName('a');


              for (var iA = 0; iA < aTags_.length; iA++)


              {


                      if (aTags_[iA].href && aTags_[iA].href.indexOf('https://myDomain.service-now.com/time_card.do?sys_id=') == 0)


                      {


                              var glide_fields = document.getElementsByTagName('th');


                              for (var iG = 0; iG < glide_fields.length; iG++)


                              {


                                      if (glide_fields[iG].getAttribute('glide_field'))


                                      {


                                              if ((


                                                      glide_fields[iG].getAttribute('glide_field') == 'time_card.total' ||


                                                      glide_fields[iG].getAttribute('glide_field') == 'time_card.sunday' ||


                                                      glide_fields[iG].getAttribute('glide_field') == 'time_card.monday' ||


                                                      glide_fields[iG].getAttribute('glide_field') == 'time_card.tuesday' ||


                                                      glide_fields[iG].getAttribute('glide_field') == 'time_card.wednesday' ||


                                                      glide_fields[iG].getAttribute('glide_field') == 'time_card.thursday' ||


                                                      glide_fields[iG].getAttribute('glide_field') == 'time_card.friday' ||


                                                      glide_fields[iG].getAttribute('glide_field') == 'time_card.saturday'


                                                      ) && glide_fields[iG].classList.contains('text-align-left'))


                                              {


                                                      glide_fields[iG].classList.remove('text-align-left');


                                                      glide_fields[iG].classList.add('text-align-right');


                                              }


                                      }


                              }


                              break;


                      }


              }


      }, 2000);


})();



Bam.   Very little overhead.


If it works... Thanks for sharing.



Hopefully the DOM doesn't change.