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

ChrisR November 17, 2019

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
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 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

ChrisR November 19, 2019

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 19, 2019

Where you are placing your script, in behaviours?

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

ChrisR February 6, 2020

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

Thank you I will try again.

0 votes
Peter DeWitt
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 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 

ChrisR November 17, 2019

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.

Suggest an answer

Log in or Sign up to answer