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.
Badges are a great way to show off community activity, whether you’re a newbie or a Champion.Learn more
This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...
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!
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