Hi Community,
I have successfully created a behaviour within serverside script. Its purpose is to present or hide and additional field based on the value of another field. It works perfectly on creation but does not work on screen transition. I have scoured the internet and came across this post......
https://library.adaptavist.com/entity/limit-a-behaviour-to-a-specific-screen-in-jira
......but have no idea how to integrate this into my current script or even if its the right thing to do??
My script is as follows.... (also attached :) )
def field = getFieldByName("IFU Current Version")
def SiteTypeOtherField = getFieldByName("IFU Current Version - Explanation")
def value = field.getValue()
if (value == "No") {
// Show this fields
SiteTypeOtherField.setHidden(false).setRequired(true)
return
}
else if (value != "No") {
// Dont show this field
SiteTypeOtherField.setHidden(true).setRequired(false)
}
Any help would be greatly appreciated!
Hi Darren.
You seem to have missed the title of the screen:
final String screenName = 'Some Screen Name'
if (fieldScreen.name == screenName) {
def field = getFieldByName(fieldName)
field.value == expectedValue ? field.clearError() : field.setError('This is not a valid value')
}
Sorry Max. The page i came across that i mentioned above does something different than i want to do but it does talk about screens
All i want is my code above to be run on a screen. I dont need any of the other stuff about "this is not a valid value".
So if i wanted to run my code above just on a screen what would the code look like?
Thanks for help :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.fields.screen.FieldScreen
@BaseScript FieldBehaviours fieldBehaviours
final String screenName = 'Test' //your transition screen name
def field = getFieldByName("IFU Current Version")
def SiteTypeOtherField = getFieldByName("IFU Current Version - Explanation")
def value = field.getValue()
if(fieldScreen.name == screenName){
if(value != null && value == "No") {
SiteTypeOtherField.setHidden(false)
SiteTypeOtherField.setRequired(true)
}
else{
SiteTypeOtherField.setHidden(true)
SiteTypeOtherField.setRequired(false)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, hope it's ok for me to use this thread and not start a new one...
So I have tried this script as I require, on a transition screen, fields to be mandatory. This I can do.
The part I'm struggling with is:
There is a field Radio button Know error with option Yes and No.
If Yes is selected then the field Know error detail should be visible and mandatory.
If option is "none" and No, then the field should not show.
Should the scripting be placed within the initialise field or the Know error field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Natasja,
I do not quite understand, you want to hide the field in which you select the value?
Usually, in practice, a field is hidden depending on the value of another field. For example: Field 1 with the value Yes, hides Field2.
In this case, the script is applied to "Field1".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have two fields.
Known error -> with options yes and no, and this field is mandatory.
There is a field Known error description, that needs to be completed if the option "Yes" is selected in the Know error field, else the field should not show on the screen.
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.
Yes it's mapped.
This is the initialiser field detail as well.
This is where I set the other fields to be mandatory
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You don't need to write the same condition for the same transition, it's enough to write the condition once and set the mandatoryness of all fields inside.
You can also set it to be mandatory using the switch,
Example:
Here is a brief about the work of the initializer:
https://scriptrunner.adaptavist.com/latest/jira/tutorials/behaviours-tutorial.html
Test the script without an initializer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need the fields to only be mandatory when the status is changed from "In progress" to "Under review".
Thus on the "Under review" screen.
If I use the Switch for the fields, then it's not working as expected.
It sets the fields to be mandatory regardless or status.
You don't need to write the same condition for the same transition, it's enough to write the condition once and set the mandatoryness of all fields inside. ->How do I do this?
Error message about current scope already contains value for fieldToRequire.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks the "Known error" and "Known error description" fields are now working as expected.
Will ensure I double check spelling.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You don't need to write the same condition for the same transition, it's enough to write the condition once and set the mandatoryness of all fields inside. ->How do I do this?
Since you have it on the screen, only give a name based on the name of the field.
Example:
def investigationTeamField = getFieldByName("Investigatin Team")
def generalObservationField = getFieldByName("General observation")
def rootCauseFild = getFieldByName("Root Cause")
if (getActionName() == "Under Review") {
investigationTeamField.setRequired(true)
generalObservationField.setRequired(true)
rootCauseFild.setRequired(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much for all your help.
All working as expected.
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.