- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
I couldn't find a good example of how to change the sort order on a related list, so I thought I could post one.
I did it via a Client Script, so it happens after loading the form. I also had to set the Type to onChange instead of onLoad because the onLoad didn't work. I would presume it is because the Related List isn't rendered in time for the onLoad Client Script, so the script had nothing to sort. However, it appears that modifying the onChange script a little accomplishes the same thing.
Anyways, here it is:
Name: Sort by Created
Active: True
Global: True
Type: onChange
Table: {table name}
Field Name: {A field that is present on the form}
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//only run on load, if I used the onLoad type of client script, it didn't work for some reason. I would presume it ran before the related list was available.
//You could also remove this IF statement to have the sort order enforced every time the field is changed and onLoad
if (!isLoading) {
return;
}
var relatedList = {tableName}.{relatedTableName}.{fieldName} //You'll need to set this. Example: "problem.incident.problem_id" Here is a resource to help figure this value out: http://www.servicenowguru.com/scripting/client-scripts-scripting/reload-form-related-list-client-scr...
if(GlideList2.get(relatedList)){//verify the related list exists
GlideList2.get(relatedList).sortDescending('sys_created_on');//set the sort order on the related list
}
}
If you know another way, let me know
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.