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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
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.