set Group picker field using groovy in post function is not working
My code is working if i test script from script fields and also updating value in database, when i use same code from create post function values are not saving to database
did i miss anything?
Here is the code:
import com.atlassian.jira.component.ComponentAccessor; 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.ComponentManager; import com.atlassian.jira.issue.ModifiedValue; import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem; import com.atlassian.jira.issue.util.IssueChangeHolder; import com.atlassian.jira.issue.util.DefaultIssueChangeHolder; import com.atlassian.crowd.embedded.api.Group; import com.atlassian.jira.user.util.UserUtil; try{ customFieldManager = ComponentManager.getInstance().getCustomFieldManager() cfCustomerId = customFieldManager.getCustomFieldObjectByName("Customer ID") cfCustomerIdValue = issue.getCustomFieldValue(cfCustomerId) userUtil = ComponentManager.getInstance().getUserUtil() cfTestGroupPicker = customFieldManager.getCustomFieldObjectByName("Test Group Picker") cfTestGroupPickerValue = issue.getCustomFieldValue(cfTestGroupPicker) Map<String, ModifiedValue> modifiedFields = issue.getModifiedFields(); FieldLayoutItem fieldLayoutItem = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem( cfTestGroupPicker); DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder(); Group groupValue = userUtil.getGroupObject("customer_"+cfCustomerIdValue); List<Group> groupList = new ArrayList<Group>() groupList.add(groupValue) cfTestGroupPicker.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cfTestGroupPicker), groupList), issueChangeHolder); cfTestGroupPickerValue = issue.getCustomFieldValue(cfTestGroupPicker) log.debug("cfTestGroupPickerValue...."+cfTestGroupPickerValue) } catch(Exception all) { log.error("Exception While updating group custom field : "+all) }
I do not see method called issue.setCustomField ( cfTestGroupPicker ), assuming you are referring to setCustomFieldValue():
I have added following to my script, but when I create an issue I got the following error on UI, no error in the logs
Error creating issue: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB
Any idea? Same script works fine from Script Fields
import com.atlassian.jira.component.ComponentAccessor; 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.ComponentManager; import com.atlassian.jira.issue.ModifiedValue; import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem; import com.atlassian.jira.issue.util.IssueChangeHolder; import com.atlassian.jira.issue.util.DefaultIssueChangeHolder; import com.atlassian.crowd.embedded.api.Group; import com.atlassian.jira.user.util.UserUtil; try{ customFieldManager = ComponentManager.getInstance().getCustomFieldManager() cfCustomerId = customFieldManager.getCustomFieldObjectByName("Customer ID") cfCustomerIdValue = issue.getCustomFieldValue(cfCustomerId) userUtil = ComponentManager.getInstance().getUserUtil() cfTestGroupPicker = customFieldManager.getCustomFieldObjectByName("Test Group Picker") cfTestGroupPickerValue = issue.getCustomFieldValue(cfTestGroupPicker) log.debug("Before cfTestGroupPickerValue...."+cfTestGroupPickerValue) Object o = "customer_"+cfCustomerIdValue issue.setCustomFieldValue(cfTestGroupPicker, o) Map<String, ModifiedValue> modifiedFields = issue.getModifiedFields(); FieldLayoutItem fieldLayoutItem = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem( cfTestGroupPicker); DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder(); Group groupValue = userUtil.getGroupObject("customer_"+cfCustomerIdValue); log.debug("groupValue..."+groupValue); List<Group> groupList = new ArrayList<Group>() groupList.add(groupValue) cfTestGroupPicker.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cfTestGroupPicker), groupList), issueChangeHolder); cfTestGroupPickerValue = issue.getCustomFieldValue(cfTestGroupPicker) log.debug("After cfTestGroupPickerValue...."+cfTestGroupPickerValue) } catch(Exception all) { log.error("Exception While updating group custom field : "+all) }
Above script works fine with Script Fields by passing in Issue key in "Preview Issue Key". Using the same script in create Post function throws following error: Error creating issue: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB Please suggest, did i miss any step while creation Note: my post function is at 3rd position in create Post functions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would use:
issue.setCustomField ( cfTestGroupPicker )
This should work providing this function comes before the one that is "saves the issue and reindexes", or similar.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks Matheus... now I can actually read it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
done
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
could you please explain what is {code} macro? i have never used it before. groovy script call at 3rd position
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please use the {code} macro to format this properly. What position is the post-function?
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.