Hello,
I am using the Script Runner plugin to create a self-computed value in a field.
This field is an ID then I have to catch later.
I use Groovy to calculate the value of the field.
This ID consists of:
Once the value generated not want to be changed (I use it as original ID)
The questions are:
The code:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.MutableIssue import static java.util.Calendar.* import org.apache.log4j.Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") MutableIssue myIssue = issue CustomFieldManager cfm = ComponentManager.getCustomFieldManager() CustomField cfAutoID = cfm.getCustomFieldObject("customfield_001") CustomField cfCountry = cfm.getCustomFieldObject("customfield_002") def autoID = myIssue.getCustomFieldValue(cfAutoID) if(!autoID) { def country = myIssue.getCustomFieldValue(cfCountry)[0,1] int year = Calendar.getInstance().get(Calendar.YEAR) if(country) { myIssue.setCustomFieldValue(cfAutoID, country.toUpperCase() + "/" + myIssue.id + "/" + year) } }
in JIRA 5.2.4
Thanks!
The value of a calculated custom field is not in the database but you can still use getCustomFieldValue(). I don't really understand that part of the question.
You could be able to access custom field values before the issue is "stored"... what is the concrete class for myIssue when you script runs?
ie: log.warn myIssue.class.name
If using setCustomFieldValue, add myIssue.store at the end. But this is a post-function?
The question is confusing because you're talking about a scripted field, AND a post-function in the same question. Can we break these out into two questions?
EDIT: If you want to do it in a post-function, AND you need the issue ID, put your post-function LAST.
Then update your custom field using this code:
def changeHolder = new DefaultIssueChangeHolder(); targetField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(targetField), "my new value"), changeHolder);
Where "my new value" is subsitute your calculated value based on the issue ID and other custom field values. Sample that I used for testing: https://gist.github.com/4542341
sorry if it is a bit confusing.
I mean I've tried two different ways.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
I'm working together with Samuel on this issue and the issue we encounter is the following:
At the same time an issue is created we are looking to create a unique reference to the issue that doesn't change even if you move it to another project. We're trying to use a script that gets the internal database ID of the issue and combine it with other variables (as shown in original question) and save it in a custom text-field.
We are finding that in the create post-event the script is not able to save the calculated value to a custom field.
The script does the "calculation" but somewhere in the creation process the value is lost.
We have tried to put the script before the Creates the issue originally post function in JIRA, but then obviously the issue doesn't have any issue.id.
We have tried to put the script after this post-function but then the value doesn't get saved in our custom field (probably because the issue was already saved).
Any suggestion on how to work around this catch-22?
thanks!
Jacques.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there...
For the unique identifier can't you just use a scripted field containing just "issue.id" - the id value of an issue doesn't change.
I'll give you an example of doing it with a CF or a post-function, although people normally pay for this level of support!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok... I updated my answer with sample code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.