Groovy compare original with edited CF values

Hey,

A user can edit an issue.

The issue includes a start and end date.

If the issue is in a certain state (X), the changes don't mather.

The issue can be transitioned to state Y from X.

If the user changes something there to the dates, it depends.

If the edited dates are between the original dates, the issue may stay in Y.

(Soo the issue is started later or ended earlier.)

If the edited dates are greater, or period changed, the issue has to go back to state X.

Question now is: is there any syntax and what is it, to get the 'old' values of an editted CF?

Old=previous, not the 1ste values.

And how can I set the states according to this?

I'm working in JIRA 4.2.

TY! :D

5 answers

1 accepted

Isn't possible on JIRA 4.2 :(

1 vote

Memes are good, but if you tag the question correctly with the plugin's tag, you will get more attention!

originalIssue.getCustomFieldValue(customfield) will work in a validator only.

For post-functions, it depends on the ordering of the functions, if your function comes before "store and reindex" you can retrieve the issue from the database using IssueManager and check the field values on that.

If it's after "store and reindex", you need to use ChangeHistoryManager to look through the issue's changes.

Thanks. :D

I tried first with tag 'groovy', but I just need a script (don't have to be groovy).


ATM, from the moment an issue in state Y is editted, it goes back to state X.


If I do it before the reindex, what's the syntax to get custom fields from the issueManager?

Something like this? :s

import com.atlassian.jira.component.*;
import com.atlassian.jira.issue.*;
import com.atlassian.jira.issue.fields.*;

IssueManager im = new IssueManager();
Date oldStartDate = im.get(Start Date);
Date oldEndDate = im.get(End Date);

Thanks!

there is a lot of sample code for getting custom field values... you need CustomFieldManager, then issue.getCustomFieldValue(customfield)

so

issue.getCustomFieldValue('Start date').value
issue.getCustomFieldValue('End date').value
originalIssue.getCustomFieldValue('Start date').value
originalIssue.getCustomFieldValue('End date').value

?

You need ChangeHistoryManager to get at previous values.

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.Issue 
   
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()

def orgStartDate=changeHistoryManager.getChangeItemsForField(issue, "Start date").find{}?.getCreated()
def orgEndDate=changeHistoryManager.getChangeItemsForField(issue, "End date").find{}?.getCreated()

def newStartDate=changeHistoryManager.getChangeItemsForField(issue, "Start date").find{}?.getCreated()
def newEndDate=changeHistoryManager.getChangeItemsForField(issue, "End date").find{}?.getCreated()

if(orgStartDate<=newStartDate&&newEndDate<=orgEndDate){
}
else{ 
    return "ERROR"
}

Something like this?

Jamie: to be honest, I like your plugin, but I miss the explanation of the syntax.

You give some examples, but that's not clear enough.

I need to know what are the possible methods, parameters, data types etc.

So if you could explain these, that would be helpfull. TY! :)

Says enough?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

233 views 1 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you