Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy compare original with edited CF values

Sir Be
April 16, 2014

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

0 votes
Answer accepted
Sir Be
May 5, 2014

Isn't possible on JIRA 4.2 :(

1 vote
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
April 21, 2014

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.

Sir Be
April 21, 2014

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!

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
April 21, 2014

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

Sir Be
April 22, 2014

so

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

?

Sir Be
April 27, 2014

Doesn't work

Sir Be
April 27, 2014

Sir Be
April 27, 2014

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
April 27, 2014

You need ChangeHistoryManager to get at previous values.

Sir Be
April 28, 2014
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! :)

Sir Be
May 12, 2014

0 votes
Sir Be
April 21, 2014

....

0 votes
Sir Be
April 17, 2014

Says enough?

Suggest an answer

Log in or Sign up to answer