Hi Team,
def errorText = "For the Ticket Type Bug, if the Sprint field is set, the Fix Version/s and Release Date are mandatory. "
def sprintField = getFieldByName("Sprint")
def fixField = getFieldByName("Fix Version/s")
def releaseField = getFieldByName("Release Date")
def sprintValue = sprintField.getValue()
if (sprintValue != "")
{
releaseField.setRequired(true)
fixField.setRequired(true)
releaseField.setError(errorText)
fixField.setError(errorText)
}
else
{
releaseField.setRequired(false)
fixField.setRequired(false)
}
I need to ensure that the "fix version" and "release date" fields are mandatory when the "sprint" field is not empty. I've attempted to achieve this using the following ScriptRunner behavior. When we populate the sprint value and provide values for the fix version and release date fields, it's displaying an error. Is there something wrong with this script? This script is commonly used in various scenarios.
Hi @Lakshmi S
For your requirement, you must ensure that you create a Server-Side Behaviour configuration for the Sprint field.
Below is a working code for your reference:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def storyPoints = getFieldByName('Story Points')
def storyPointsValue = storyPoints.value
def fixedVersions = getFieldById('fixVersions')
def sprint = getFieldByName('Sprint')
def sampleDate = getFieldByName('Sample Date')
fixedVersions.required = false
sprint.required = false
sampleDate.required = false
if (storyPointsValue) {
fixedVersions.required = true
sprint.required = true
sampleDate.required = true
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.
Below is a screenshot of the Behaviour configuration:-
I am also including a couple of test screenshots for your reference:-
1. When the Create screen is first loaded, and no value is set to the Story Points field, the fields are not set to mandatory as shown in the screenshot below:-
2. However, if a value is added to the Story Points field, the Fix Version/s, Sprint and Date field is set to required as shown in the screenshot below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Sorry @Ram Kumar Aravindakshan _Adaptavist_ for confusing. Its not based on story points, if the "Sprint" field is not empty, the fix version and Release Date are mandatory.
I used this script, but not working.
def errorText = "For the Ticket Type Bug, if the Sprint field is set, the Fix Version/s and Release Date are mandatory. "
def sprintField = getFieldByName("Sprint")
def fixField = getFieldByName("Fix Version/s")
def releaseField = getFieldByName("Release Date")
def sprintValue = sprintField.getValue()
if (sprintValue != "")
{
releaseField.setRequired(true)
fixField.setRequired(true)
releaseField.setError(errorText)
fixField.setError(errorText)
}
else
{
releaseField.setRequired(false)
fixField.setRequired(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lakshmi S
Sorry, I misread your description.
So if it's for the Sprint field, the code is pretty much the same, only set the if condition based on the Sprint field's value like below:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def sprint = getFieldById(fieldChanged)
def sprintValue = sprint.value
def storyPoints = getFieldByName('Story Points')
def fixedVersions = getFieldById('fixVersions')
def sampleDate = getFieldByName('Sample Date')
fixedVersions.required = false
storyPoints.required = false
sampleDate.required = false
if (sprintValue) {
fixedVersions.required = true
storyPoints.required = true
sampleDate.required = true
}
Please note, the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.
Below is a screenshot of the Behaviour configuration:-
Below are a couple of test screenshots for your reference:-
1. When the create screen first appears none of the fields are set to required as shown below:-
2. If the value from the Sprint list is selected, all the other fields will be set to required as shown below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
Were you able to create the ticket ? its showing mandatory but its not allowing to create a ticket.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lakshmi S
I don't seem to be encountering this problem in my environment.
The error message you are getting suggests that you haven't updated the Behaviour code according to your environment.
From the screenshot you shared, the Release Notes field is set as required, but the error message indicates that the Release Dates field is mandatory.
Please double-check if your code is updated according to the fields you are using in your environment and ensure that all the fields that have been set to required have a value so the ticket can be created.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lakshmi S
Has your question been answered?
If yes, please accept the answer provided.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.