Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to sort given value in groovy.

Jason Li Ting Chung February 21, 2021

Hi Community,

In scriptrunner, I am having problem to sort the value these 2 variables: "participants" and "cfValpart"

For the following line:
if (participants != cfValpart){
.....
}

The comparison is made but the value needs to be in order. Take for examples the following 2 mentioned scenario:
Scenario 1:
participants =

{John, Pierre, Alana}
cfValpart = {John, Pierre, Alana}

The comparison return true.
But Scenario 2:
participants =

{John, Pierre, Alana}

cfValpart =

{Pierre, John, Alana}

The comparison return false. (Where it should be true)

I have use to the following ".order" but the cfValpart is not accepting the function.

Can I have some advise or help on the issue

Best regards,
Jason Li

1 answer

1 vote
Gareth Cantrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2021

Hi @Jason Li Ting Chung 

As long as both variables are Lists of the same type (eg. String), then you can use something like: 

if (participants.sort() != cfValpart.sort()) {
...
}

If not, use the groovy .collect { .. } construct to extract the values you want to compare into a List of Strings.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events