on ‎2021 Nov 22 2:28 PM
Hello,
I want to sort an array of dates in SAP IRPA, but I did not find a way to switch variables in my array when a date is prior to another one.
I tried using set variable value activity, but it is not possible to access my array at a certain index (array[index] "is not an alphanumeric value or underscore").
I also thought about using add value to list, but it adds at the end of the list and not at an expected index.
Finally, I tried a basic JS customed script, but it fails to assign values to my declared structure data type, as it is (supposedly) a constant value..
thanks for helping,
Théo
Request clarification before answering.
theohaastrup
In Custom script write the below code:
const dates = [{po: '81001', date: new Date('2021-06-28')},
{po: '81005', date: new Date('2021-06-10')},
{po: '81002',date: new Date('2021-06-05')}];
const sortedDates = dates.sort((a, b) => a.date - b.date );
return sortedDates;define output parameter sortedDates in custom script and loop it and display values using log message

now sortedDates will come in output

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sandeep,
Thank you for your answer, but my array is imported in the script as an input value, do you know if it is like a pointer to this array ? or just a local copy in the script ? because in this case I would have to return the sorted array to replace the original, but set variable value activity does not support this action:

Do you know an alternative ?
Théo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.