Hi,
I need a bit of help on a behavior.
What i want to do: to create users, i need to set a certain set of groups to the user. I have some CFs :
- Available groups (Group Picker (multiple groups), ID 13110)
- New user - User type (drop-down)
- New user - Main project (Project Picker (single project), ID 13143)
i have added the behavior to show/hide the "New user - Main project" field when non internal user type is selected, now i want to retrieve the group that is set on the "Service Desk Customer - Portal Access" project role of the project selected on the "New user - Main project" dropdown.
I have the following code in the behavior script area:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.ProjectRoleManager
ComponentManager componentManager = ComponentManager.getInstance()
ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager
def ProjectSelectedField = getFieldById(getFieldChanged())
def selectedOption = ProjectSelectedField.getValue().toString().split(": ")[1] as String
Project selectedProjectObj = ProjectManager.getProjectByCurrentKeyIgnoreCase(selectedOption)
def groupsField = getFieldByName("Available groups")
// name of role here
ProjectRole custRole = projectRoleManager.getProjectRole("Service Desk Customer - Portal Access")
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(custRole, selectedProjectObj)
log.info "$selectedProjectObj.key, $selectedProjectObj.name, $selectedProjectObj.ProjectLead, ${actors.getUsers()*.name}\n";
When i select the value in the GUI, i have the following error in the log:
2018-06-27 18:52:56,722 http-nio-8080-exec-79502 ERROR g.moscalu 1132x30991261x2 10s3ksm <IP> /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.jira.behaviours.BehaviourManagerImpl] *************************************************************************************
2018-06-27 18:52:56,724 http-nio-8080-exec-79502 ERROR g.moscalu 1132x30991261x2 10s3ksm <IP> /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: (create issue) project/issuetype: RJADM/RJADM - Access, user: g.moscalu, fieldId: customfield_13143, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.project.ProjectManager.getProjectByCurrentKeyIgnoreCase() is applicable for argument types: (java.lang.String) values: [TMONE]
at Script1.run(Script1.groovy:15)
Can I get some help to fix this?
I got the same error with getProjectByCurrentKey, getProjectByCurrentKeyIgnoreCase, getProjectObjByKeyIgnoreCase and i'm out of ideas - i am probably missing something...
I assume that by retrieving the group object from the role, i could add it to the "Available groups" collection quite easily, but i'm not there yet...
Running SR 5.4.12, on JIRA 7.3.6 & SDesk 3.5.0
Hi Gabriel,
The static part of the error might be the reason here. Have you tried getting an instance of project manager instead of accessing it in a static way?
ProjectManager pm = ComponentAccessor.getProjectManager()
then using pm object on the same method?
Cheers
Thanks!
After changing to :
import com.atlassian.jira.component.ComponentAccessor
[....]
ProjectManager pm = ComponentAccessor.getProjectManager()
Project selectedProjectObj = pm.getProjectByCurrentKeyIgnoreCase(selectedOption)
I no longer have the error!
Can you also help with the last issue i have? The "${actors.getUsers()*.name}" resolves all the way down to the users that are members of the group, while i want to only get the group object...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks!
After changing to :
import com.atlassian.jira.component.ComponentAccessor
[...]
ProjectManager pm = ComponentAccessor.getProjectManager()
Project selectedProjectObj = pm.getProjectByCurrentKeyIgnoreCase(selectedOption)
I no longer have the error!
Can you also provide a hint on how to get the project role group ? the "${actors.getUsers()*.name}" resolves all the way down to the actual users, and i only want the group object (to be added on the CF "Available groups")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
do you have any suggestion on how to get the group defined on project role?
The "${actors.getUsers()*.name}" resolves all the way down to the actual group members... and i need to add the group to the "Available groups" group picker CF...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again!
That would allow you to retrieve Group type actors and you can iterate on the set returned to get group names. The String to filter on groups is defined here:
Should be ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE :)
Hope this helps!
Cheers
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.