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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

How to get previous changed custom field data.

Hi All,

I have custom field X of type multi-text. I'm creating another scripted field Y which displays the X previous data using script runner.

Please let me know any sample script to achieve this.

 

TIA!

 

 

2 answers

1 accepted

1 vote
Answer accepted

Hello,

You can find an answer here:

https://community.atlassian.com/t5/Jira-questions/How-to-get-previous-and-current-values-of-all-the-changed-fields/qaq-p/269702

The base script is like this:

def changeHistoryManager = com.atlassian.jira.component.ComponentAccessor.getChangeHistoryManager()
def created = changeHistoryManager.getChangeItemsForField(issue, "your custom field name")

Thank you @Alexey Matveev _cPrime_

Here is my code 

import com.atlassian.jira.component.ComponentAccessor
def changeHistoryManager = com.atlassian.jira.component.ComponentAccessor.getChangeHistoryManager()
def old = changeHistoryManager.getChangeItemsForField(issue, 'Original Requirement')
return old.fromString

This code prints all the previous data used in that field in a square brackets

Example : [text]

if the custom field is null then it print empty square bracktes [].

My Question is,

1. How to get only last changed value in the output instead of getting old data from the beginning.

2. How do I eliminate these brackets in output?

 

TIA!  

If you get brackets in groovy it means that the class of the old variable is the List. You need to get an element from the list. If you want to get the last element you should write:

old?.last().fromString

If you want to get the first element then:

old?.first().fromString

Hello @Alexey Matveev _cPrime_  - This is amazing. 

Is there anyway to extract the date as well as the field values?

Also, if we wanted each change separated for easier viewing, something better than just the comma, can that be done as well? 

Thanks in advance for any help.

SMK

@SMAtlassianMber Did you get any workaround to separate the change based on Date or with any sort by order?

Suggest an answer

Log in or Sign up to answer
TAGS

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