I am trying to get user name from a JIRA custom filed and put it into a group . how can i achieve this using groovy or any postfunction in jira .I am trying to do this using Workflow post-function . Any other solution is welcome .
Eg : field A = user1
i want to add "user1" to group "Jiraxyz" .
help
Abyakta
Here is code for script postfunction provided by ScriptRunner plugin:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.security.groups.GroupManager import com.atlassian.jira.user.ApplicationUser Issue issue GroupManager groupManager = ComponentAccessor.getGroupManager(); groupManager.addUserToGroup( ((ApplicationUser) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("field name"))).getDirectoryUser() , groupManager.getGroup("groupName") )
@Vasiliy Zverev @Vasiliy Zverev above code is giving error .
failed on issue: ABCD-5989, actionId: 11, file: <inline script>
java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object
at Script23.run(Script23.groovy:9)
What i did :
I pasted the above code with groupName and customfield change in the postfunction.
Let me know if i am doing anything wrong
Abyakta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This error namely means that custom field is empty to given issue. Here is updated code to fix this case:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.security.groups.GroupManager import com.atlassian.jira.user.ApplicationUser GroupManager groupManager = ComponentAccessor.getGroupManager(); try { groupManager.addUserToGroup( ((ApplicationUser) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("field name"))).getDirectoryUser() , groupManager.getGroup("groupName") ) } catch (NullPointerException e){ }
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.
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.