Jira 6.0.8. How do I set my own value to a custom field?
Is it going to be a post function?
PS: Later on, I am going to change Original Estimate field. So, I want to learn basing on text-based custom fields.
Thanks!
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder CustomField field1 = customFieldManager.getCustomFieldObject(new Long(15900)); String currentFieldValue = issue.getCustomFieldValue(field1); String newFieldValue = "New value for this text field"; field1.updateValue(null, issue, new ModifiedValue(currentFieldValue, newFieldValue), new DefaultIssueChangeHolder());
This code (implemented as a post-function) does not change my CF value. It's a Text Field (single line). Is it supposed to?
Using groovy, you could do something like this:
CustomField field1 = customFieldManager.getCustomFieldObject(new Long(11807)); String currentFieldValue = issue.getCustomFieldValue(field1); String newFieldValue = "New value for this text field"; field1.updateValue(null, issue, new ModifiedValue(currentFieldValue, newFieldValue), new DefaultIssueChangeHolder());
You just need to replace 11807 in the first line to whatever the id of your field is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use it as a post-function script or in a listener.
What problem are you having when you try to make it work?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I prefer to use some groovy, please. Can you show a sample source?
customfield_10901 - is of text type. So, how do I change its value?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi et,
I know this is a very old question but still I would like to provide a sample code to use in script listner on issue update event. In below code, 'Dev Time Estimate' is a text field where estimate is provided in the format 1m, 2w, 3d format. And the the 'Dev Time Estimate in hours' is numeric field this field is use in boards for estimation as board estimation is restricted to Text fields. So the below code converts the text field value into numeric value in terms of hours. Thanks!
import javax.mail.*;
import javax.mail.internet.*;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.label.LabelManager;
import com.atlassian.jira.issue.label.Label;
MutableIssue currentIssue = (MutableIssue)event.getIssue();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager();
//Issue issue = issueManager.getIssueObject("ANT-1495" );
def devTimeEst = customFieldManager.getCustomFieldObjectByName("Dev Time Estimate");
def devTimeEstVal = event.issue.getCustomFieldValue(devTimeEst).toString();
int devTimeEstValLength = devTimeEstVal.length()
int timePosDev = 0;
Double hoursDev = 0
def hoursDevTimeEst = customFieldManager.getCustomFieldObjectByName("Dev Time Estimate_in hours");
// Calculate Dev Time Estimate
// If the value provide is a number, consider it to be an hour value
if (devTimeEstVal.isNumber()) {
hoursDev += (Double.valueOf(devTimeEstVal));
}
else {
for (int i = 0; i < devTimeEstValLength; i++) {
if (devTimeEstVal.charAt(i) == 'w') {
hoursDev += (Double.valueOf(devTimeEstVal.substring(timePosDev, i)) * 5 * 8);
if ((i + 1) < devTimeEstValLength) {
timePosDev = i + 2;
}
}
else if (devTimeEstVal.charAt(i) == 'd') {
hoursDev += (Double.valueOf(devTimeEstVal.substring(timePosDev, i)) * 8);
if ((i + 1) < devTimeEstValLength) {
timePosDev = i + 2;
}
}
else if (devTimeEstVal.charAt(i) == 'h') {
hoursDev += (Double.valueOf(devTimeEstVal.substring(timePosDev, i)));
if ((i + 1) < devTimeEstValLength) {
timePosDev = i + 2;
}
}
else if (devTimeEstVal.charAt(i) == 'm') {
hoursDev += (Double.valueOf(devTimeEstVal.substring(timePosDev, i)) * 60);
if ((i + 1) < devTimeEstValLength) {
timePosDev = i + 2;
}
}
else {
continue;
}
}
}
currentIssue.setCustomFieldValue(hoursDevTimeEst, hoursDev)
//update database
currentIssue.store();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey,
check this plugin:
https://marketplace.atlassian.com/plugins/com.googlecode.jira-suite-utilities
You can update CF using a post-function.
Cheers
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.