Hi
I have two groups.
First group: if a user from first group is creating the JSM ticket, no validation, go and ahead and create the issue
Second group: if the user is from second group, show a custom field with group of users in it. Make it required. then submit the ticket.
I am new to scriptrunner.
1. Do I have to use a Validator or should I a use scriptRunner behaviour to acheive this?
Hi and welcome to the wonderful world of scriptrunner!
Let's clarify some components of Jira/Scriptrunner.
1) Workflow Validator: whether provided by native Jira functionality, scriptrunner, or any other add-on, workflow validators execute AFTER the user clicks submit on a transition screen but before anything is saved.
2) Behaviours: can be executed any time an issue screen is displayed (creation, edit, or transition screens). This can be used to validate user entries or otherwise adjust elements on the screen based on user input. Note that fields have to be present on the screen for behaviours to do something to it. A field can be hidden (or not). But a new field can't be added.
Similarly, behaviours can make a field required when it is not otherwise set as required by the field config or the workflow. But it cannot make it optional if it is required by those other components.
So since your requirement is to "Show" a field when a user is part of group 2, what we really need then is to HIDE it when the user is NOT part of group 2. This can be accomplished with a behaviour script.
Because your requirement is not dependent on another field being modified, then the best place to put this logic is in an "initializer" script. This script runs when the screen initially opens.
Here is a sample script to get you going in your behaviour journey:
def conditionalCustomFieldName = 'Your custom field to show'
def groupToShowFieldTo = 'group 2'
def currentUser = Users.loggedInUser
def behaviourFormField = getFieldByName(conditionalCustomFieldName)
def showField = currentUser.isMemberOfGroup(groupToShowFieldTo)
behaviourFormField.setRequired(showField).setHidden(!showField)
This presumes that your custom field exists, is on the screen, and is not required by Jira configurations. Also, that field must already be configured to allow the correct type of input. s
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.