Highlighted
New Member.
1264 views

JS function to call the rtecall for sort

Jump to solution

I have an Array Structure and I need a JavaScript function to call the rte call to "Sort".

could some one pls let me know how can I achieve this?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: JS function to call the rtecall for sort

Jump to solution

Hi @sunny5

Try like bellow 

var _p = print;
sortExample(['09/28/15 08:40:02', '07/02/15 08:40:00', '07/08/15 08:40:03'])
function sortExample(dateArray){
	var dateSortAsc = function (date1, date2) {
  	if (new Date(date1)  < new Date(date2)) return -1;
  	if (new Date(date1) > new Date(date2)) return 1;
  	return 0;
	};//function dateSortAsc
_p(dateArray.sort(dateSortAsc));
}

View solution in original post

8 Replies
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: JS function to call the rtecall for sort

Jump to solution
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: JS function to call the rtecall for sort

Jump to solution

HI. @sunny5

You can use JS method sort 

Here the exampe with variable 

var _p = print;
sortExampe()
function sortExampe(){
_p(vars['$lo.ucapex']) // [C++ object Datum] - {"partial.key", "SysAdmin", "SQLAdmin", "SOAP API", "user.favorites", "MySM", "ICT Member" }
_p(vars['$lo.ucapex'].toArray().sort()) // ICT Member,MySM,SOAP API,SQLAdmin,SysAdmin,partial.key,user.favorites
}

  

Highlighted
New Member.

Re: JS function to call the rtecall for sort

Jump to solution

is there a way to sort the date field?

(I'm using a free text instead of using a DATE field.)

0 Likes
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: JS function to call the rtecall for sort

Jump to solution

@sunny5 

Here it is 

var _p = print;

sortExample(['09/28/15 08:40:02', '09/28/15 08:40:00', '09/28/15 08:40:03'])
function sortExample(dateArray){
_p(dateArray.sort());//ASC => 09/28/15 08:40:00,09/28/15 08:40:02,09/28/15 08:40:03
_p(dateArray.reverse());//DSC => 09/28/15 08:40:03,09/28/15 08:40:02,09/28/15 08:40:00
}

HTH. 

0 Likes
Highlighted
New Member.

Re: JS function to call the rtecall for sort

Jump to solution

this doesn't really sort on DATES

var _p = print;

sortExample(['09/28/15 08:40:02', '07/02/15 08:40:00', '07/08/14 08:40:03'])
function sortExample(dateArray){
_p(dateArray.sort());//ASC
}

output:

07/02/15 08:40:00,   07/08/14 08:40:03,    09/28/15 08:40:02

 

0 Likes
Highlighted
New Member.

Re: JS function to call the rtecall for sort

Jump to solution

this will work only if the date is passed in YY/MM/DD format

0 Likes
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: JS function to call the rtecall for sort

Jump to solution

Hi @sunny5

Try like bellow 

var _p = print;
sortExample(['09/28/15 08:40:02', '07/02/15 08:40:00', '07/08/15 08:40:03'])
function sortExample(dateArray){
	var dateSortAsc = function (date1, date2) {
  	if (new Date(date1)  < new Date(date2)) return -1;
  	if (new Date(date1) > new Date(date2)) return 1;
  	return 0;
	};//function dateSortAsc
_p(dateArray.sort(dateSortAsc));
}

View solution in original post

Highlighted
New Member.

Re: JS function to call the rtecall for sort

Jump to solution

thank you so much! it works!!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.