Hi,
Im trying to add a custom script to the create issue transition to validate if a user doesnt have the projectrole administrator and the issue type is Initiative. If so, an exception should be thrown.
Resulting in the following code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.opensymphony.workflow.InvalidInputException
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
if (issue.issueType.name == "Initiative" && !projectRoleManager.isUserInProjectRole(currentUser, projectRoleManager.getProjectRole("Administrators"), issue.getProjectObject())) {
throw new InvalidInputException("Only users in the Administrator project role are allowed to create Initiatives.")
}
But I'm getting the following error:
2018-09-25 10:15:21,877 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-09-25 10:15:21,877 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: devProjectRole for class: Script60 at Script60.run(Script60.groovy:9)
I have no idea what I'm doing wrong as the code looks flawless to me. Any ideas? Thanks in advance!
Hello @Rick van Twillert _TMC_
Where you place this code? Is this validator?
As i can see this code should work. Try to log everything, this may help you to understand what goes wrong.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.opensymphony.workflow.InvalidInputException
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
log.error("issue type: ${issue.issueType.name}")
log.error("currentUser: ${currentUser.getName()}")
log.error("progetcrole: ${projectRoleManager.getProjectRole("Administrators").getName()}")
log.error("Project: ${issue.getProjectObject().getName()}")
if (issue.issueType.name == "Initiative" && !projectRoleManager.isUserInProjectRole(currentUser, projectRoleManager.getProjectRole("Administrators"), issue.getProjectObject())) {
throw new InvalidInputException("Only users in the Administrator project role are allowed to create Initiatives.")
}
Thanks for the suggestion for debugging Mark! I already tried this, but just for the getProjectRole method, without any hint.
After updating ScriptRunner the latest version, the script was working correctly. v5.4.14 to 5.4.28 on Jira 7.12.1
I was using our acceptance environment. Possibly some caching issue or other acceptance test might've conflicted... I can't explain it yet.
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.