I am needing to write a custom groovy script post function to update and store a custom field value to the database. (I originally used Scripted Fields successfully, but need a way to access the values for custom emails/etc). I am fairly new to this so am having trouble getting values to update on my ticket. Below is the code I am using where my custom field is a numeric field.
Any ideas on what I'm doing wrong?
import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.IssueChangeHolder import com.atlassian.jira.issue.util.DefaultIssueChangeHolder ComponentManager componentManager = ComponentManager.getInstance(); CustomFieldManager customFieldManager = componentManager.getCustomFieldManager(); CustomField travelcost=customFieldManager.getCustomFieldObject(“customfield_11705”); def valuetravelcost = issue.getCustomFieldValue(travelcost) def changeHolder=new DefaultIssueChangeHolder(); travelcost.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(travelcost),1), changeHolder);
This code should be enough, anyway the usage depends on the place.
If your code is placed in the postfunction, there is just enough to use issue.setCustomFieldValue(travelcost, value), when your postfunction is placed before built-in function Update change history for an issue and store the issue in the database (beware that Create transition is slightly different case).
Otherwise - your maybe just not reindexed.
The above code is placed on a non-Create transition. I had the code above in a post function before the Update Change History for an Issue..." post function. There is a Re-index an issue to keep indexes in sync with the database post function directly following the update post function. It still doesn't work. I also tried issue.setCustomFieldValue(travelcost,1) instead of the updateValue line. That too isn't populating the value. I'm out of ideas.
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.