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

This widget could not be displayed.

Isn't possible on JIRA 4.2 :(

This widget could not be displayed.

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

?

Doesn't work

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! :)

This widget could not be displayed.

Says enough?

This widget could not be displayed.

....

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

154 views 1 3
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