Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Display only selective from dropdown

I have a case where I need to make couple of field values from the drop down visible to  only 1 group and these should be hidden for other groups.

The first group can view all values but 2 should not be visible to rest of them

 

Please suggest 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Leo Community Leader Sep 12, 2019

Hi @Arun,

 

You can achieve this through ScripRunner Behavior plugin, and below code will help you on the same

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor

//Get Relevant field and options manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def groupManager = ComponentAccessor.getGroupManager()

//Get select list field and it's options
def selectList = getFieldByName("Field Nmae") //Field name which you want to restrict values
def customField = customFieldManager.getCustomFieldObject(selectList.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String groupName = "YourGroup" //place the group here to validate

if (groupManager.getUsersInGroup(groupName).contains(user)) {
def optionsMap = options.findAll {
it.value in ["Value 1", "Value 2", "Value 3"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}
else{
def optionsMap = options.findAll {
it.value in ["Value 1"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}

 

BR,

Leo

Please see below and correct me

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script69.groovy: 21: unexpected token: Review @ line 21, column 53.
, Iteration Test, State Code Review, UA
^

1 error

 

My inputs:

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor

//Get Relevant field and options manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def groupManager = ComponentAccessor.getGroupManager()

//Get select list field and it's options
def selectList = getFieldByName(Phase) //Field name which you want to restrict values
def customField = customFieldManager.getCustomFieldObject(selectList.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String groupName = VRIN //place the group here to validate

if (groupManager.getUsersInGroup(groupName).contains(user)) {
def optionsMap = options.findAll {
it.value in [ Unit Test , Iteration Test, State Code Review, UAT ] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}
else{
def optionsMap = options.findAll {
it.value in [Unit Test, Iteration Test] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}

Leo Community Leader Sep 12, 2019

Hey @Arun,

If this is your exact code, then you should try with "" in below places

1. def selectList = getFieldByName(Phase)

  >>def selectList = getFieldByName("Phase")

2. String groupName = VRIN

  >> String groupName = "VRIN"

it.value in [ Unit Test , Iteration Test, State Code Review, UAT ]

  >>it.value in [ "Unit Test" , "Iteration Test", "State Code Review", "UAT" ]

4. it.value in [Unit Test, Iteration Test]

  >> it.value in ["Unit Test", "Iteration Test"]

 

BR,

Leo

Thanks Leo, I tired the quotes and got this below

No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getFieldByName() is applicable for argument types: (java.lang.String) values: [Phase]

Please advise.

Arun

Leo Community Leader Sep 13, 2019 • edited

Hey Arun, Can you share me the screen shot of full script with error you are getting. attached my script with console

behavior-selectlist.png

Leo Community Leader Sep 13, 2019

humm, it's weird. Are you trying this code in Behavior plugin? 

I do not have Behavior plugin, ran it in Script console and also in Script Fragments where I was able to see the issue. Please advise.

Adaptavist ScriptRunner for JIRA - Installed version: 5.5.7.1-jira8 

Leo Community Leader Sep 13, 2019

This explains the issue, the given code is written with behaviours module

And if I'm not wrong, Behaviours is one of the extensions of ScriptRunner, you'll find it under manage apps, attaching screenshot of the behaviour location

 

Create new Behaviour --> Add your Field --> Add given script in server side script(you'll find this option once you added field) --> Add mapping(map your project and issue types/ leave with all issue types if it's not for particular issue types)

 

behaviours-jira.png

Great, this worked. Thank you Kindly!

Leo Community Leader Sep 13, 2019

Glad you achieved it :) 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June ask me anything (AMA)

Hello Community members! We’re wrapping up the end of JSM June with an Ask Me Anything (AMA) with the Jira Service Management product team. This is your chance to ask all your ITSM questions to o...

109 views 7 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you