I have this almost working, but can't seem to get the line highlighted in Red below to work. It is saying that this code was deprecated in v7.0. I have tried several other options, but I'm not able to get this working.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.user.UserManager
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
def constantsManager = ComponentAccessor.getConstantsManager()
def userUtil = ComponentAccessor.getUserUtil()
log.debug ComponentAccessor.getComponent(UserManager)
def currentUser = ComponentAccessor.JiraAuthenticationContext.getLoggedInUser()
if (! userUtil.getGroupNamesForUser(currentUser.name).contains("Group")) {
def allowedPriorities = constantsManager.getPriorityObjects().findAll {
it.id.toInteger() > 2
}.collectEntries {
[(it.id): it.name]
}
getFieldById(PRIORITY).setFieldOptions(allowedPriorities)
}
Here is what I was following: https://scriptrunner.adaptavist.com/4.3.0/jira/recipes/behaviours/restricting-priority-and-resolution.html
Appreciate any insight!
-Nick
Hi Nick,
You should change the line in red to become the line below for JIRA 7.
def allowedPriorities = constantsManager.getPriorities().findAll() {
I hope this helps.
Thanks
Kristian
Hi Kristian,
Thanks for the help! I've changed the line in my script and the script validates fine now. However, it's still not working as expected. I've mapped the serverside script to my test project and tested it out with several groups that I am in. I've also experimented with changing the it.id.toInteger to be greater than 10, which should only show me the Blocker priority. However, when I create an issue, it's still showing me all of the priorities in the drop down.
Any idea what I'm doing wrong?
Thanks,
Nick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nick,
Looking at your script it looks as if the issue is where you are checking for the group for the user.
Have you tried using the example of the Adaptavist website as I have used the example of the website with the changed line above and this works on my local JIRA 7 instance.
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kristian,
Do I create this as an initializer or a serverside script?
If I use serverside script, which field do I put this on? I've tried priority and it does not work. I've also tried initialiser and that doesn't work either.
I'm using the "Jira-developers" group that's used in the example as well.
Thanks,
Nick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nick,
This should be set as a behaviour on the priorities field.
I would say the issue is with the group not being found. Can you please check that jira-developers group is valid in your instance.
I am away from desk at the moment but will look to post an example of how I have this working in my local instance tomorrow.
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That would be appreciated.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nick,
I have attached below the example code that I have used to restrict priorities to all users in the jira-software-users group. I notice you are using the jira-developers group as per in the example but in JIRA 7 this does not exist and was replaces with the jira-software-users group.
Below is my script along with some screenshots of how it is configured and works.
Code:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.sal.api.user.UserManager import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY def constantsManager = ComponentAccessor.getConstantsManager() def userUtil = ComponentAccessor.getUserUtil() log.debug ComponentAccessor.getComponent(UserManager) def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() if (userUtil.getGroupNamesForUser(currentUser.name).contains("jira-software-users")) { def allowedPriorities = constantsManager.getPriorities().findAll() { it.id.toInteger() > 2 }.collectEntries { [(it.id): it.name] } getFieldById(PRIORITY).setFieldOptions(allowedPriorities) }
Config:
Screen Shot 2016-09-16 at 16.37.58.png
Priorities before script was added:
Screen Shot 2016-09-16 at 16.34.43.png
Priorities after script was added:
Screen Shot 2016-09-16 at 16.38.33.png
I hope this helps
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much, Kristian!
It works now. Not sure what was different between our scripts because it is now working for any group I put in there. Really appreciate your help.
-Nick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you, Jamie.
I've replied to Kristian below. He had a fix for the line of code, but it still does not seem to be working properly. Any idea?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The code is deprecated but should still work fine. Slavishly trying to use non-deprecated code is often not worth it for Atlassian apps imho. Does it not work?
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.