Using OrderBy method multiple time in Script?

Vivek Verma
Mega Sage
Mega Sage

Hi Experts,

I need to understand the, How to use OrderBy method multiple times in script.

find_real_file.png

11 REPLIES 11

Aniket Sawant
Mega Expert

Hi,

 

orderBy(String name)

Specifies an orderBy column.

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:

NameTypeDescription
nameStringThe column name used to order the records in this GlideRecord object.

Return:

TypeDescription
voidMethod 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)

Specifies a decending orderBy column.

Parameters:

NameTypeDescription
nameStringThe column name to be used to order the records in a GlideRecord object.

Return:

TypeDescription
voidMethod 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

Hi Aniket,

 

Thank you for the quick response.

But in these examples method is calling only once in time.

Namrata Khabale
Giga Guru

Hey Vivek ,

 

orderBy(String fieldName)

Specifies a field name to be used to order the query set. This may be called more than once to order by multiple fields.

Example:

 function UpdateProjectWBS(project) {
  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');
}

 

 
For More information Refer the Link:
 

Mark my Answer Correct and Helpful if it works for you.

Thanks

Namrata


 

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?