Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

322 views 9 7
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