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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

extract certain keys and values from change Edited

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

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

changeHistoryManager.getChangeItemsForField(issue, "status").collect {
[
"fromString": it.fromString,
"toString": it.toString
]
}

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]]

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"}

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]]

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
TAGS
Community showcase
Published in Trello

🏊‍♀️ Atlympic Event: Trello

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

109 views 1 11
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you