We have a groovy script that we use in the post functions of the create transition for setting values to hidden fields. The values show up on the screen, but are not being saved in the database. If you go into the edit screen, the values show as none.
We are using JIRA 6.4 and the updated Groovy script module
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.customfields.view.CustomFieldParams import com.atlassian.jira.issue.transport.CollectionParams import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.util.ImportUtils import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.fields.CustomFieldImpl import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem //import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.event.type.* //MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject('PRD-3876') ComponentAccessor componentAccessor = new ComponentAccessor() CustomFieldManager customFieldManager = componentAccessor.getCustomFieldManager() IssueManager issueManager = componentAccessor.getIssueManager() CustomField customField = customFieldManager.getCustomFieldObjectByName("Type : Sub Type") Object value = issue.getCustomFieldValue(customField) HashMap<String, Option> hashMapEntries = (HashMap<String, Option>) value if (hashMapEntries != null) { parent = hashMapEntries.get(CascadingSelectCFType.PARENT_KEY) child = hashMapEntries.get(CascadingSelectCFType.CHILD_KEY) } CustomField insParent = customFieldManager.getCustomFieldObjectByName("Type-Type") CustomField insChild = customFieldManager.getCustomFieldObjectByName("Subtype-Subtype") DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder() def modifiedValueP = new ModifiedValue(issue.getCustomFieldValue(insParent), parent) def modifiedValueC = new ModifiedValue(issue.getCustomFieldValue(insChild),child) insParent.updateValue(null, issue, modifiedValueP, changeHolder) insChild.updateValue(null, issue, modifiedValueC, changeHolder)
You should try to save the modified issues using issueManager.
It is very likely that updateValue() will only set the value in the object, but will not persist that to the database. I'd reckon that issueManager provides a save(), update() or similar method to persist the changes. (I don't have the JIRA code here with me, so I can't give you the specifics, but it may give a hint where to start.)
I put this at the end of the script, but it still doesn't save the issue into the database. issueManager.updateIssue(null, issue, EventDispatchOption.ISSUE_UPDATED, true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for asking, but if the field is Hidden how do you see it on the screen? This may be related to another feature of JIRA where you can't modify a field via the API if it is Hidden - at least it was a feature a few versions ago.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I made it un-hidden so I could see the values. Normally it is hidden so we can use the two fields to query on. The custom field is a cascading field to organize issues. We split it out into two other fields to query on. We can see the information on the screen, but in the edit it says none and if you save it, it will set the values to the two fields to none. For some reason, we can't get it to save in the database.
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.