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

How can I pre-set a check box on a check list based on Role on transition?

I have an approval check list and would like to pre-check based on the role of the assignee when I transition is opened.

Example: Check List is...

                 Manager Approval

                 Test Team Approval

                 UI Team Approval

                 Deployment Approval

 

I have a transition called Manager Approved and when the transition screen comes up I would like to see the Manager Approval check box already checked.

2 answers

0 votes
Peter DeWitt Community Leader Nov 17, 2019

@ChrisR , check out this Atlassian document on configuring customer fields. The section on Contexts should be most helpful.

https://confluence.atlassian.com/adminjiraserver/configuring-a-custom-field-938847235.html

-pjd 

no, I've looked at contexts and that only seems to apply to issue types and project types, which will not work in my case.

0 votes
Leo Community Leader Nov 17, 2019

Hi @ChrisR ,

you can do that through ScriptRunner's Behaviour. below snippet may help you 

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

//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 chkBox = getFieldByName("Test Checkbox") //Field name which you want to restrict values
def customField = customFieldManager.getCustomFieldObject(chkBox.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager)

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def role = projectRoleManager.getProjectRole("Administrators") //fetching role to validate
def admin = projectRoleManager.isUserInProjectRole(user, role, issueContext.getProjectObject()) //validating currentuser is part of admin role or not


if(getFieldScreen().name == "Screen Named added in your workflow transition"){ //This is to enable this script only on your workflow transition, in case if you don't want to run on create/edit screen. if not you can remove this condition
if(admin){
def optionToSelect = options.find {it.value == "Value 2"}
chkBox.setFormValue(optionToSelect*.optionId)
}else{
def optionToSelect = options.find {it.value == "Value 1"}
chkBox.setFormValue(optionToSelect*.optionId)
}
}

 

BR,

Leo

Thank you for the code example but I have been unable to get it working. I do not do a lot of scripting so I am a bit unfamiliar with what I am looking at.

I'm seeing various errors: 

Cannot find matching method

com.atlassian.jira.security.roles.ProjectRoleManager#isUserInProjectRole

Leo Community Leader Nov 19, 2019

Where you are placing your script, in behaviours?

can I have your complete code or the screen shot with error message?

No I had not learned much about behaviors but am looking into that option now.

Thank you I will try again.

Suggest an answer

Log in or Sign up to answer
TAGS

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