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

Scriptrunner Scripted field - How to verify if 'description' is edited during an active sprint? Edited

Hi,

During an active sprint, if an issue description is edited then I would like to increment a counter, to know how many times description has been updated.

For this, I wrote the below piece of code to verify, if the issue is in active sprint or not. If the particular issue is in active sprint then the script should be looking for any updates to the 'description field' and update the counter. 

Any ideas on how to validate if the description field is edited (updated), during an active sprint?

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.greenhopper.service.sprint.Sprint

def description = issue.getDescription();

def sprintstatus =

    (issue.getCustomFieldValue(

ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Sprint")

) as List).any {

(it as Sprint).active

}

if(sprintstatus == true) //if sprint is active

{

   //check if the 'description' field of the issue is edited and if edited then increment the counter for every edit

}

2 answers

1 accepted

0 votes
Answer accepted

Hi @Chandu 

I can't provide all code, but I can give a clue on this one.

You cahev to use ChangeHistoryManager

import com.atlassian.jira.issue.changehistory.ChangeHistoryManager

and of course get it

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

then you can get every change item history against the description field

changeHistoryManager.getChangeItemsForField(issue, IssueFieldConstants.DESCRIPTION)
List<ChangeItemBean>

but you need to import in order to use it

import com.atlassian.jira.issue.IssueFieldConstants

This method returns the list of ChangeItemBean

List<ChangeItemBean>

ChangeItemBean has every information you need, date/time, old value, new value.

If you check the sprint start date then you will have the exact number which the counter would have.

I hope it was helpful.

Thanks

Tuncay

Hi @Tuncay Senturk _Snapbytes_ - Thank you for your response!

 I figured out the way to do this. Thank you for your suggestion on <ChangeItemBean>

Perfect! I'm glad to hear that it helped.

Hi @Chandu,

Not sure how you are using the script in your Jira. If you have Scriptrunner, then you can use Script listener to listen to the Issue Updated event. Next, within the script, you can defined what are the checks you want to do; for example, for creation issue types and etc. The script would something like this:

import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.greenhopper.service.sprint.Sprint

def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)

def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "description"}


log.debug(change)


if (change) {
    //log.debug("Old value : ${change.oldstring}")
    //log.debug("New value : ${change.newstring}")
    log.debug("Value changed by ${event.user} at ${event?.getChangeLog()?.created}")

def sprintstatus = (issue.getCustomFieldValue(ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Sprint")) as List).any {
        (it as Sprint).active
    }

    if(sprintstatus == true) {//if sprint is active
        log.debug("Sprint is active")
// you can add some codes here to increase the counter, if you have a custom field with the counter value,
// then you will need to read the field value and increment by one and then store the value back into the custom field
    }
}

I have tested it on the bare minimum level. I hope that it helps.

Thanks,
Moga

Hi @mogavenasan  - Thank you for your response!

Like mogavenasan likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

4,570 views 12 8
Join discussion

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