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.

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

If "Due Date" contains a value, then "XYZ" field is mandatory

Nag
Contributor
March 2, 2021

Hi There,

Here is the behavior script I'm creating

script would look like this for now:

def sourcefield = getFieldById("duedate")
def targetField = getFieldByName("XYZ")

targetField.setRequired(false)

if (sourcefield.getValue()){
    targetField.setRequired(true) 
} else {
    targetField.setRequired(false)
}

 

The field "Due Date" is a system field and there was a bug (SRJIRA-2758) where you can't get a system field form field by its name. You have to get by its ID instead:

def sourcefield = getFieldById("duedate")

However, it was fixed in ScriptRunner 6.19.0. I highly recommend for you to upgrade as there are a quite number of bugs that have been fixed from 6.12.0.

 

Regards, Eswar

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 3, 2021

Hi @Nag 

Your code seems like "if Due Date field has no value, then XYZ will be required"

Did you try changing as below

targetField.setRequired(false)
if (sourcefield.getValue()){
targetField.setRequired(true)
}
Nag
Contributor
March 4, 2021

Hi @Tuncay Senturk 

Appreciate your quick response.

Sorry just tried, didn't work.

I just need to check if date field contains a value?

Please advise.

Suggest an answer

Log in or Sign up to answer