Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Not Working : Sprint Value is set to value, Fix Version and Release Date fields are mandatory

Lakshmi S
Contributor
August 15, 2024 edited

Hi Team,

 




sprint.png

 


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.

 

 

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 16, 2024

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:-

behaviour_configuration.png

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:-

test1.png

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:-

test2.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

 

 

 

Lakshmi S
Contributor
August 16, 2024

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)

   

   }

 

sprint.png

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 16, 2024

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:-

behaviour_config.png

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:-

test1.png

2. If the value from the Sprint list is selected, all the other fields will be set to required as shown below:-

test2.png

 

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

 

Lakshmi S
Contributor
August 19, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Were you able to create the ticket ? its showing mandatory but its not allowing to create a ticket.

sprint.png

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 20, 2024 edited

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

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 22, 2024

Hi @Lakshmi S

Has your question been answered?

If yes, please accept the answer provided.

 

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

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
AUG Leaders

Upcoming Jira Events