Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

No signature of method: static com.atlassian.jira.project.ProjectManager.getProjectByCurrentKeyIgnor

Gabriel MOSCALU June 27, 2018

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

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
miikhy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 27, 2018

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

Gabriel MOSCALU June 27, 2018

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...

Gabriel MOSCALU June 27, 2018

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")

0 votes
Gabriel MOSCALU June 27, 2018

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...

miikhy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 27, 2018

Hi again!

I'd go with https://docs.atlassian.com/software/jira/docs/api/7.1.8/com/atlassian/jira/security/roles/DefaultRoleActors.html#getRoleActorsByType-java.lang.String-

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:

https://docs.atlassian.com/software/jira/docs/api/7.1.8/com/atlassian/jira/security/roles/ProjectRoleActor.html

Should be ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE :)

Hope this helps!

Cheers

0 votes
Gabriel MOSCALU June 27, 2018

Confirmed!

TAGS
AUG Leaders

Atlassian Community Events