It's not the same without you
Join the community to find out what other Atlassian users are discussing, debating and creating.
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.
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.
Read moreAtlas Camp is our developer event which will take place in Barcelona, Spain from the 6th -7th of September . This is a great opportunity to meet other developers and get n...
Connect with like-minded Atlassian users at free events near you!
Find a groupConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.
Start an AUGYou're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.