Hi,
I am using the following Custom Script to set a value for single value Group Picker in my post-function:
It is not giving any error, but is not setting the value as well.
import com.atlassian.crowd.embedded.api.Group import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import java.util.List; CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); def customerName = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_12345")); ComponentManager componentManager = ComponentManager.getInstance(); Group watcherGroup = componentManager.getUserUtil().getGroup( customerName[0]); List<Group> groupList = new ArrayList<Group>() groupList.add(watcherGroup); def cf = customFieldManager.getCustomFieldObjectByName("Test Group Picker"); issue.setCustomFieldValue(cf, [groupList]); issue.store();
Thanks
I suspect it's what you're doing with customfield_12345 - you seem to be treating it as an array (implying a multi-option field of some sort), but then as though the elements are strings, which they won't be.
What type of field is it? And what do you expect it to be?
(And who is Reg?)
I have even printed the value of the Group picker custom field at the end of the script and is displaying the correct value but in '[]'like '[jira-users]'
log.warn(issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Group Picker"))*.name)
Just the value is not being displayed on the ticket (I have the custom field on the view screen of JIRA ticket). Is it because of the [] brackets or am I missing something else?
Also I have added the custom script after the post-function 'Creates Issue' and before 'Fire Create Issue event' in the workflow.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A string is not the same as a multi-option.
You need to work out exactly what this nfeed field is returning as a java object - is it an array of strings? Is it an list of JIRA options? Is it a collection of nfeed option objects?
From your use of [] I suspect you've done part of this and discovered it is a collection of some form, and then tried to use it as such (because collection[0] will return the first object in the collection) but you need to work out what the objects actually are.
If it were a standard JIRA custom field, I could tell you, but I don't know what nfeed returns when asked for a field value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
nFeed field returns an array of strings.
M concern is that when I display the value of the group picker custom field (copied from nFeed field), it shows the correct value in square brackets. It just does not show on he screen(the custom field is present on the screen).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure that it is, but there's a really easy way to confirm it. Could you try
log.warn ( customerName )
log.warn ( customerName[0] )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nic,
Forget the nFeed field. Even if I try to hard code a JIRA group, it does not work
import com.atlassian.crowd.embedded.api.Group import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import java.util.List; def customFieldManager = ComponentAccessor.getCustomFieldManager() def groupManager = ComponentAccessor.getGroupManager() def watcherGroup = groupManager.getGroup("jira-developers") def cf = customFieldManager.getCustomFieldObjectByName("Test Group Picker") issue.setCustomFieldValue(cf, watcherGroup) log.warn(watcherGroup) log.warn(cf) issue.store(); log.warn(issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Group Picker"))*.name)
Thanks,
Rupa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The code I've got for storing a value is different and may be worth trying instead:IssueChangeHolder changeHolder =
new
DefaultIssueChangeHolder();
cf
.updateValue(
null
, issue,
new
ModifiedValue(issue.getCustomFieldValue(cf), watcherGroup), changeHolder)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jeetu,
Here is the modified script that I believe should work for you. This is working for me using JIRA 7.4.1
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
//Get Issue Object
Issue issue = issue //The issue object is internally retrieved in the post-function
//Get instance of Custom Field Manager
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
//Initialize variables to setup group picker & automation type custom field value
def groupManager = ComponentAccessor.getGroupManager()
def singleGroupCf = customFieldManager.getCustomFieldObject("customfield_12700")
def group = groupManager.getGroup(<YOUR JIRA USER GROUP NAME>)
List groupList = new ArrayList()
groupList.add(group)
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
singleGroupCf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(singleGroupCf), groupList), changeHolder)
issue.store()
Hope it helps.
Cheers,
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anupam ,i am using this script for creating permissions based on the group.I have different workflows for both parent ticket and sub ticket.I am facing issues when i am modifying the parent ticket as sub ticket.because its not adding the respective users to group.do you have any solution for this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems that nFeed claim they do not support programmatic access to their data. Please see: NFEED-652
That makes sense as it could be backed by any data source and i'm not sure how nFeed reads and stores that data.
You'll want to raise this with plugin vendor of nFeed to see what they say.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Adam,
This is not a nFeed issue. We are using a similar script to set Issue Security Level and it works fine.
Even if I do not read the value from nFeed and just add a hard-coded group name say 'jira-users', the script still does not work.
Thanks,
Rupa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actual script used without nFeed:
import com.atlassian.crowd.embedded.api.Group import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import java.util.List; def customFieldManager = ComponentAccessor.getCustomFieldManager() def groupManager = ComponentAccessor.getGroupManager() def watcherGroup = groupManager.getGroup("jira-developers") def cf = customFieldManager.getCustomFieldObjectByName("Test Group Picker") issue.setCustomFieldValue(cf, watcherGroup) log.warn(watcherGroup) log.warn(cf) issue.store(); log.warn(issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Group Picker"))*.name)
The script is being used in the 'Create' transition of the workflow and placed after 'Creates Issue Originally' 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.