Trigger a client script when related list is sorted
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have a form with a related list. I have a client script on this form. I would like to run the script whenever the related list gets sorted (user clicks the column header on the list to sort it by that column). I'd also like to run that script when cells on the related list change.
Does anyone know how to do this? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
ahoy @noproblems,
could you possibly explain what would be some benefit of this? Is this a real requirement or solely for learning purposes?
If real requirement, I'd push back as it is not worthy the efforts, following the smart customisations, you should only do custom codes only if the benefit will overweight (or at least balance) the development and future maintenance efforts. And I am worried it's not applicable in this use case...
If learning purposes, then client script might not be the best approach.
I still think it's not a good idea, but to answer your question: whenever a list is sorted by any field/column and order (AZ/ZA) then it is stored in the User Preference table, first as a new record then updated accordingly:
To learn how this works - you can open two windows: one with any list of your choice (incident in my example) and second with the user preferences: https://yourDomain.service-now.com/sys_user_preference_list.do
Then anytime you sorted that list, then update the preference table to see how it changes.
But this what I have shared will be creating/updating the preference records no matter if it is "regular" list or related list.
Hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hello @noproblems
Interesting use case for sure!
I believe there is no such client script type which can detect the related list's column header sorted event. However, if there is one I would love to learn and understand that.
When any related list's column header is sorted, then a record is created in the user preferences. Here is an example of "Task SLAs" related list in the Incident Form:
Maybe you can play with the above just for learning.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @noproblems
As per my knowledge, ServiceNow does not provide a native out-of-the-box event that fires when a user sorts a related list.
"
- The sorting order is saved as a user preference per table not per list.
- However, If you feel that the above requirement can be implemented as new features in the upcoming releases, Please submit an enhancement request for the same.
- [Steps to create Enhancement Request can be found here >>KB0755878 - Idea Management for customer enhancement requests ]
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0755878"
Refer: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0964468