extract certain keys and values from change

Samar Elsayed June 15, 2021

Hi 

 

I am using the below in a scripted field

changeHistoryManager.getChangeItemsForField(issue, "status") 

 

which is returning the below  :

 

[com.atlassian.jira.issue.history.ChangeItemBean@4cbf004a[fieldType=jira,field=status,from=10002,fromString=In Development,to=10009,toString=Blocked,created=2021-06-12 01:06:52.792], com.atlassian.jira.issue.history.ChangeItemBean@1c19d69c[fieldType=jira,field=status,from=10009,fromString=Blocked,to=10184,toString=In Design,created=2021-06-12 01:07:05.427], com.atlassian.jira.issue.history.ChangeItemBean@785e386e[fieldType=jira,field=status,from=10002,fromString=In Development,to=10009,toString=Blocked,created=2021-06-12 01:35:41.529], com.atlassian.jira.issue.history.ChangeItemBean@4ee968a0[fieldType=jira,field=status,from=10009,fromString=Blocked,to=10008,toString=Done,created=2021-06-12 01:36:08.516], com.atlassian.jira.issue.history.ChangeItemBean@7a608c67[fieldType=jira,field=status,from=10008,fromString=Done,to=10021,toString=Cancelled,created=2021-06-12 01:37:32.262], com.atlassian.jira.issue.history.ChangeItemBean@289f1881[fieldType=jira,field=status,from=10002,fromString=In Development,to=10009,toString=Blocked,created=2021-06-12 01:42:44.575], com.atlassian.jira.issue.history.ChangeItemBean@218bc8b4[fieldType=jira,field=status,from=10009,fromString=Blocked,to=10184,toString=In Design,created=2021-06-12 01:43:02.087], com.atlassian.jira.issue.history.ChangeItemBean@2422184d[fieldType=jira,field=status,from=19123,fromString=Requires Design,to=10184,toString=In Design,created=2021-06-12 01:56:11.607], com.atlassian.jira.issue.history.ChangeItemBean@5a5fbb1a[fieldType=jira,field=status,from=10002,fromString=In Development,to=10009,toString=Blocked,created=2021-06-12 02:04:08.493]]

 

I need to know how I can extract only the fromString and toString and their values and save them in a list/map in the same order they appear above. 

the list I mean is like for example :

[[fromString=In Development, toString=Blocked ] , [fromString=Blocked, toString=Cancelled ] ]

1 answer

1 accepted

1 vote
Answer accepted
Max Lim _Adaptavist_
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.
June 15, 2021

You can use following snippet to return a List<Map>:

changeHistoryManager.getChangeItemsForField(issue, "status").collect {
[
"fromString": it.fromString,
"toString": it.toString
]
}
Samar Elsayed June 15, 2021

thank you! @Max Lim _Adaptavist_ 

one more question :

 

how can I remove consecutive duplicate values that fit this condition and only keep one of them :

keep any transition that has In Development  and remove the duplicates in the transitions where from and to are anything else other than In Development 

so for example here is the list  :

[[fromString:Ready for Dev, toString:In Development], [fromString:In Development, toString:Blocked], [fromString:Blocked, toString:In Design], [fromString:In Design, toString:Requires Design]]

 

and after removing the duplicates that fit the condition :


[[fromString:Ready for Dev, toString:In Development], [fromString:In Development, toString:Blocked], [fromString:In Design, toString:Requires Design]]

Max Lim _Adaptavist_
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.
June 16, 2021

Are you saying you only want values with "in Development" in "fromString" and "toString" keys?

You can do this:

changeHistoryManager.getChangeItemsForField(issue, "status").collect {
[
"fromString": it.fromString,
"toString": it.toString
]
}.findAll {it.fromString == "In Development" || it.toString == "In Development"}
Samar Elsayed June 17, 2021

No not find , I mean something like unique values of from and to together based on a condition like :

( it.toString != "In Development" ) && (it.fromString != "In Development" && it.toString != "Backlog" && it.toString != "Ready for Dev" )

so for example in this  list  :

[[fromString:Ready for Dev, toString:In Development], [fromString:In Development, toString:Blocked], [fromString:Blocked, toString:In Design], [fromString:In Design, toString:Requires Design]]

we have 2 consecutive elements that fit the condition which are :

[fromString:Blocked, toString:In Design], [fromString:In Design, toString:Requires Design]

so unique should return one of  so in the end, it look like that :

 

[[fromString:Ready for Dev, toString:In Development], [fromString:In Development, toString:Blocked], [fromString:In Design, toString:Requires Design]]

Max Lim _Adaptavist_
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.
June 17, 2021

I not sure if I understand your condition. To apply only on consecutive items, I think you have to use a for loop to achieve that.

Perhaps, the toUnqiue(closure) or toUnique(comparator) methods could achieve this too.

Suggest an answer

Log in or Sign up to answer