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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 5 hours ago in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

17 views 0 3
Read article

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