- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 10:06 PM
Hi,
I want to add filter condition to sort tickets by created date means sort it from z-a.
Could you please help me to achieve this by script include. This script include I have to call in filter condition.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 10:40 PM
HI @Ashwini Jadhao ,
I trust you are doing great.
- Go to the "System Definition" module in ServiceNow and click on "Script Includes."
- Click on "New" to create a new Script Include.
- Provide a name for the Script Include, such as "TicketSortUtils."
- In the script section, you can use the following code:
var TicketSortUtils = Class.create();
TicketSortUtils.prototype = {
initialize: function() {},
sortByCreatedDateDescending: function(query) {
query.orderByDesc('sys_created_on');
},
type: 'TicketSortUtils'
};
- Save the Script Include.
Now, you can use this Script Include in the filter condition of your ticket queries to sort them by created date in descending order.
Here's an example of how you can use this Script Include in a filter condition:
var sortUtils = new TicketSortUtils();
sortUtils.sortByCreatedDateDescending(current);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 11:40 PM
Hi,
Not sure why you want to call it from Script Include.
If your code is running on Server Side then you can use it like below:
var rec = new GlideRecord('table_name');
rec.orderBy('sys_created_on'); // if want to sort A-Z
// rec.orderByDesc('sys_created_on'); // if wanto to sort Z-A
rec.query();
while (rec.next()) {
return rec.column_name;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 10:40 PM
HI @Ashwini Jadhao ,
I trust you are doing great.
- Go to the "System Definition" module in ServiceNow and click on "Script Includes."
- Click on "New" to create a new Script Include.
- Provide a name for the Script Include, such as "TicketSortUtils."
- In the script section, you can use the following code:
var TicketSortUtils = Class.create();
TicketSortUtils.prototype = {
initialize: function() {},
sortByCreatedDateDescending: function(query) {
query.orderByDesc('sys_created_on');
},
type: 'TicketSortUtils'
};
- Save the Script Include.
Now, you can use this Script Include in the filter condition of your ticket queries to sort them by created date in descending order.
Here's an example of how you can use this Script Include in a filter condition:
var sortUtils = new TicketSortUtils();
sortUtils.sortByCreatedDateDescending(current);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 11:40 PM
Hi,
Not sure why you want to call it from Script Include.
If your code is running on Server Side then you can use it like below:
var rec = new GlideRecord('table_name');
rec.orderBy('sys_created_on'); // if want to sort A-Z
// rec.orderByDesc('sys_created_on'); // if wanto to sort Z-A
rec.query();
while (rec.next()) {
return rec.column_name;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 11:54 PM
Thank you Teju and Amit for your help!
I am preferring the 2nd way to use it directly in my business rule, not using script include.