cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP IRPA array variable switch

ITUSER
Explorer
0 Likes
1,384

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

Accepted Solutions (0)

Answers (2)

Answers (2)

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

ITUSER
Explorer
0 Likes

Hello Sandeep, do you have an answer to my previous post ?

ITUSER
Explorer
0 Likes

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:

capture.png

Do you know an alternative ?

Théo