Sorting the related list items ?

peterg157
Kilo Contributor

Hi Frinds,

How to sort the related list items based on a filed ?

Thanks.

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

You can set a default order with a user preference, but that doesn't preclude users from clicking the header and choosing their own sort field/order.


The easiest way I know to set the default preference is to set it yourself, then go to User Administration> User Preferences, sort by date updated (descending) and find the entries you just set/created (example below where I sorted the Task SLA related list on the incident form.)


find_real_file.png



Open each record and remove the user (System Administrator) and check the System field, then save. Now you have a default setting.



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


View solution in original post

5 REPLIES 5

veena_kvkk88
Mega Guru

Hi Peter,



It works the same way as a regular list. When you click on the header of the column, the list gets sorted.


Hi Veena,



Thank you for your reply.



We need it to sort automatically when form loaded instead of sorting manually.



Thanks.


In that case, you could write a before query business rule on the related list table.



Something like this: current.orderBy('you_field_name_here');



But keep in mind that any user preference will be taking a precedence to whatever sort oder you set.


That is, if a user sorts the list by clicking the header of the column once, that's going to be saved as the user preference for that user and every time the list loads, it is going to be sorted accordingly for him/her.


Chuck Tomasi
Tera Patron

You can set a default order with a user preference, but that doesn't preclude users from clicking the header and choosing their own sort field/order.


The easiest way I know to set the default preference is to set it yourself, then go to User Administration> User Preferences, sort by date updated (descending) and find the entries you just set/created (example below where I sorted the Task SLA related list on the incident form.)


find_real_file.png



Open each record and remove the user (System Administrator) and check the System field, then save. Now you have a default setting.



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