Using OrderBy method multiple time in Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 04:45 AM
Hi Experts,
I need to understand the, How to use OrderBy method multiple times in script.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 04:53 AM
Hi,
orderBy(String name)
Call this method more than once to order by multiple columns. Results are arranged in ascending order, see orderByDesc(String name) to arrange records in descending order.
Parameters:
Name | Type | Description |
---|---|---|
name | String | The column name used to order the records in this GlideRecord object. |
Return:
Type | Description |
---|---|
void | Method does not return a value |
Example
var queryString = "priority=2";
var gr = new GlideRecord('incident');
gr.orderBy('short_description'); // Ascending Order
gr.addEncodedQuery(queryString);
gr.query();
while (gr.next()) {
gs.info(gr.short_description);
}
orderByDesc(String name)
Parameters:
Name | Type | Description |
---|---|---|
name | String | The column name to be used to order the records in a GlideRecord object. |
Return:
Type | Description |
---|---|
void | Method does not return a value |
Example
var queryString = "priority=2";
var gr = new GlideRecord('incident');
gr.orderByDesc('short_description'); //Descending Order
gr.addEncodedQuery(queryString);
gr.query();
while (gr.next()) {
gs.info(gr.short_description);
}
please mark helpful or correct based on impact.
Regards,
Aniket Sawant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 04:59 AM
Hi Aniket,
Thank you for the quick response.
But in these examples method is calling only once in time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 05:09 AM
Hey Vivek ,
orderBy(String fieldName)
Example:
var count = 0;
var child = new GlideRecord('pm_project_task');
child.addQuery('parent', project.sys_id);
child.orderBy('order');
child.orderBy('number');
child.query();
var len = child.getRowCount().toString().length;
var seq = 0;
while (child.next()) {
count += UpdateProjectTaskWBS(child, 1, ++seq, len, '');
}
gs.addInfoMessage(count + ' Project Tasks updated');
}
Mark my Answer Correct and Helpful if it works for you.
Thanks
Namrata
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2024 05:59 AM
Hi!
1. What is
UpdateProjectTaskWBS
?
2. If we use "child" in script after child.query, is it the whole GlideRecord('pm_project_task') or only the part of table after query?