Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×My company is evaluating either to use Script Runner or not. One of our requirement is to only allow a certain issue created when Task, New Feature, or Improvement issue types is selected and a value (Capital) of one of the our custom field. Also, if the user selects other values of the custom field would allow to create the issue regardless of the issue type.
Scenario:
If there are other options to do this, let me know.
Thanks
Hi Rex,
I can confirm that a Simple Scripted Validator provided by the Script Runner plugin could be placed on the create transition of the issue in order to solve your requirements outlined below.
The way the validator would work would be to check to see if the Issue type was Bug and if so it would check if the Capital value had not been selected in the drop down list and only allow the issue to be created if this was the case. If the Capital value was selected when the issue type was of Bug then it would show an error to the user as shown in the screenshots below otherwise it would allow the issue to be created.
I have attached the code below along with some screenshots of how this works and should be configured below.
Code:
if (issue.issueTypeObject.name == 'Bug' && cfValues['DemoSelectList']?.value == 'Capital'){ return false }else { return true }
Config:
image2016-3-10 17:17:16.png
Result:
image2016-3-10 17:17:25.png
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad I was able to help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kristian,
Can this functionality be done in the update screen? I understand it will not be a validator. Can it be a behaviours or other functionality in Script Runner?
Thanks,
Rex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kristian,
How should I set Customfield to some value in that script?
Eg.
{ // Need to set Cf "Approving Group" to _JiraTeam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Teju,
This code is for a validator and you cannot set values in a validator.
You would need to use a post function to set the field using the Script Post function option you mentioned above.
You can find more information on post functions here.
If you need further assistance can you please raise a separate question.
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kristian,
image2016-6-6 15:36:38.png
I am researching/testing/upgrading to possible JIRA Software version 7.1.7. The screenshot above is showing. I tried to do as it suggested but I'm not able to get it right. As of right now, it still works.
Can you help me out on fixing this issue/warning error?
Thanks,
Rex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rex,
I have changed my validator above to be as per the code below and it works with JIRA 7.
if (issue.getIssueType().name == 'Bug' && cfValues['DemoSelectList']?.value == 'Capital'){ return false }else { return true }
It looks as if you are not calling the getIssueType() which is the correct method to use for JIRA 7. Also you are checking 2 issue types in the screenshot below and should look to have a seperate simple scripted validator for each issue type.
I hope this helps.
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rex,
Yes you would need to use Behaviours to implement similar functionality on the edit issue screen.
An example of how you could achieve this is shown below.
Code:
// Required Imports import com.atlassian.jira.component.ComponentAccessor // Get a pointer to my select list field def selectList = getFieldByName("DemoSelectList") // Get the Value of the Demo Select List Field def selectListVal = selectList.getValue() // If the Value is Capital throw and error if(selectListVal == "Capital"){ selectList.setError("The Capital Value can only be used for the Task, New Feature and Improvement Issue Types") }
Mapping required to only fire for Bug Issue Type:
image2016-3-21 16:28:51.png
Config:
image2016-3-21 16:29:21.png
Result:
image2016-3-21 16:30:49.png
I hope this helps
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kristian,
It's working in the create screen, how do you add it to the edit screen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rex,
Behaviours work on the create and edit screens by default but do not work when a field is inline edited.
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kristian,
The behaviour is able to work without the validator in the create screen.
Here is a scenario:
image2016-3-22 7:29:39.png
2. Edit the issue first time with the issue type of bug:
image2016-3-22 7:31:16.png
3. Issue lets it changed (behaviour didn't work)
image2016-3-22 7:32:7.png
4. Edit the issue the second time: (it has the error, but I am not able to update to another issue type or even charge type)
image2016-3-22 7:33:32.png
image2016-3-22 7:35:13.png
What do you think?
Thanks,
Rex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rex,
You may want to look at checking the issue type using code similar to below and move this to the behaviour to be on the issue type field.
// Required Imports import com.atlassian.jira.component.ComponentAccessor // Get a pointer to my fields def issueType = getFieldById("issuetype") def selectList = getFieldByName("DemoSelectList") // Get the Value of the Demo Select List Field def selectListVal = selectList.getValue() // If the issue type is bug and the Value is Capital throw and error if(issueType.getValue() == "1") { if( selectListVal == "Capital") selectList.setError("The Capital Value can only be used for the Task, New Feature and Improvement Issue Types") }else { selectList.clearError() // clear the error }
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kristian,
Unfortunately, it's still not working.
Scenario:
Scenario 2:
It's almost there, but it needs just a little more changes. Thanks for helping me.
Rex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rex,
Unfortunately when a field is changed it needs the fields need to be clicked in again for the change to be recognised and fired.
Unfortunately this is a limitation of the behaviours plugin and is something you will need to put up with if you follow the behaviours approach.
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Kristian,
I will go back to simple scripted validator for now. I am thinking of adding more JavaScript code, but it will take more work and I'm not a JavaScript master. Let me know if you can think of other ways to use script runner to my companies requirement.
Rex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry Kristian,
It was actually me in the last comment. My coworker login and I forgot to log her out.
Rex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Conditioned validator from Update on Transition for JIRA uses regular expression based condition checking that can usually accommodate requirements like these.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register Now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.