Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with Scriptrunner Behaviour script

Aisha M
Contributor
October 19, 2020

I have the below script & it behaves the below mentioned way,

* Makes a drop-down field mandatory when the current Epic Due Date value is changed to a latter date 

* Makes the drop-down field mandatory when the Epic Due Date value is completely erased 

* Hides drop-down field when the current Due Date value is changed to a earlier date

* Stays hidden when an user randomly edits an Epic issue for other field values

But the problem I have is, sometimes an user creates a new Epic without a Due Date value (Maybe they wanna add a date after sometime) . And even in that case, when they try to fill Due Date for the first time, the Reason drop-down field becomes mandatory. Is it possible to avoid in that scenario alone ? (like, when an user already created an Epic & tries adding the Due Date for the first time, I want the field to be hidden ?)

1 answer

0 votes
Leo
Community Champion
October 19, 2020

Hi @Aisha M,

you can simply place another condition to check Due Date's value. if it was null and gets value now you don't need to perform any changes, something like below

if (underlyingIssue){
def dueDate_value = underlyingIssue?.getDueDate()
if(dueDate_value){
def duedate = getFieldById("duedate").formValue
def textField = getFieldById("customfield_10002")
if (duedate != "" && dueDate_value >= duedate){
textField.setHidden(true)
textField.setRequired(false)
}
else {
textField.setHidden(false)
textField.setRequired(true)
}
}
}

 

BR,

Leo

Aisha M
Contributor
October 19, 2020

Hi @Leo , Thank you for the comment. I replaced my code with your above input. But now the behaviour doesn't work as intended. The text field doesn't become mandatory when the value is changed to a latter date

Leo
Community Champion
October 19, 2020

@Aisha M , you mean when Due date has some value and changed to later date doesn't set text field as mandatory?

Aisha M
Contributor
October 19, 2020

@Leo Yes, the text field did not become mandatory when the Due Date was changed to a latter value from the existing date. Infact, nothing happened once I replaced my code as below with the above mentioned snippet. 

import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

import java.sql.Timestamp

@BaseScript FieldBehaviours fieldBehaviours
if (underlyingIssue){
def dueDate_value = underlyingIssue?.getDueDate()
if(dueDate_value){
def duedate = getFieldById("duedate").formValue
def textField = getFieldById("customfield_10002")
if (duedate != "" && dueDate_value >= duedate){
textField.setHidden(true)
textField.setRequired(false)
}
else {
textField.setHidden(false)
textField.setRequired(true)
}
}
}

  

Leo
Community Champion
October 23, 2020

@Aisha M , I haven't modified your script except placing a condition to check whether current issue has due date or not. 

maybe you can add the condition in else part by removing it from top

 

BR,

Leo

Aisha M
Contributor
October 28, 2020

@Leo  Thank you for the comment, but I have gotten the code fixed. :)

Suggest an answer

Log in or Sign up to answer