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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,448
Community Members
 
Community Events
176
Community Groups

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
Tuncay Senturk Community Leader Feb 07, 2021

Hi @Chandana 

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 - Thank you for your response!

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

Tuncay Senturk Community Leader Feb 09, 2021

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

0 votes

Hi @Chandana,

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

Atlassian Community Events