Dynamically change column labels in a List view using JavaScript?

mewalker22
Kilo Contributor

Is it possible to dynamically change column labels in a List view using JavaScript?

1 ACCEPTED SOLUTION

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Marcus,



I hate saying "no" to questions like this, because of course there are. They are elements in the DOM, and JavaScript has the ability to arbitrarily modify the DOM. Therefore, it is possible. But the practical answer is no. For a host of reasons:


  • They are difficult to target individually
  • The names aren't necessarily unique
  • The names might be different between languages
  • Lots of things update those- from simply adding/removing columns by personalizing/configuring, to the very basic "click the header to sort it" will actually cause the elements to be rebuilt with the original names
  • Who knows if those names are carried through to anything else that relies on the original values as output in the DOM
  • The platform has no defined support for it, and so any customization that purports to do so may stop working when a UI update/upgrade is released
  • And more!


Field labels are the Labels of the columns they represent. You can translate them so they appear correctly in other languages, but trying to manipulate them after they've been rendered on a list is likely to lead to heartache and many nights of cursing.


View solution in original post

7 REPLIES 7

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Marcus,



I hate saying "no" to questions like this, because of course there are. They are elements in the DOM, and JavaScript has the ability to arbitrarily modify the DOM. Therefore, it is possible. But the practical answer is no. For a host of reasons:


  • They are difficult to target individually
  • The names aren't necessarily unique
  • The names might be different between languages
  • Lots of things update those- from simply adding/removing columns by personalizing/configuring, to the very basic "click the header to sort it" will actually cause the elements to be rebuilt with the original names
  • Who knows if those names are carried through to anything else that relies on the original values as output in the DOM
  • The platform has no defined support for it, and so any customization that purports to do so may stop working when a UI update/upgrade is released
  • And more!


Field labels are the Labels of the columns they represent. You can translate them so they appear correctly in other languages, but trying to manipulate them after they've been rendered on a list is likely to lead to heartache and many nights of cursing.


bernyalvarado
Mega Sage

Hi Marcus,



Would you mind sharing a little bit more what you're trying to accomplish? One will think that if you have a column described in a way in a list, then it would also be meaningful to see the same label on the form. Would you agree? Having said that, have you tried doing a dictionary override to change the field label? The change will be effective for both, list and forms, but as mentioned before, hopefully this is even beneficial for you and your end users.



Thanks,


Berny


Two use cases I see:


1) you dot-walk to another field ( in this case you would want to modify the form and list label ) and you want to see a different label. Example: instead of 'Location Parent' you might want 'Country'.



2) you create a database view. I've done this where all three columns in the view are 'Name', when I wanted them all to read something different.



I agree with Cory's post you could do this, but probably shouldn't ( and it would be difficult ). I'm very interested in hearing if anyone else has a supported method for displaying a different label on a list than on a form.


Hi Zachary,



There is actually a supported way to accomplish the second use-case you mentioned:


https://wiki.servicenow.com/index.php?title=Database_Views#Relabeling_a_Column