ScriptRunner behavior logic for empty Date field : error not cleared for empty date field

Veeresh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 16, 2024

I have two date and time fields start date and end date, when user trying to edit date fields if end date is less than start date should throw an error, if start date is empty then it should clear the error and allow user to enter any date in end date, also if end date is greater than start date error should clear.

I wrote below script it's working when start date is not empty, but when I empty the entire field (start date) manually, error is not cleared, but when I clear partially that is if I just remove time or anything from field partially then it's cleared the error. I'm not sure why error is not cleared when I completely emptied the start date, please suggest where I'm doing wrong, below is the script which I wrote.

I also tried for empty field

// startDateStr ==""  || startDateStr ==null || startDateStr.toString().trim().isEmpty   but nothing worked, please suggest

 

import java.lang.Exception
import org.apache.xmlgraphics.util.DateFormatUtil
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FormField
import com.onresolve.jira.groovy.user.FieldBehaviours
import java.text.SimpleDateFormat

 

def endDate = getFieldByName("End Date")
def startDate = getFieldById(fieldChanged)
def startDateValueStr = startDate.getValue() as String
def startDateValue = startDate.getValue() as Date
def endDateValue = endDate.getValue() as Date
if (!startDateValueStr) {
endDate.clearError()
}
if (startDateValue && endDateValue.before(startDateValue)) {
endDate.setError("The End Date cannot be before the Start Date.")
} else {
endDate.clearError() 
}

 

1 answer

0 votes
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.
September 17, 2024

Hi @Veeresh

I am going to assume you are using ScriptRunner's Behaviour for this.

Please share a screenshot of your Behaviour configuration so I can get a better understanding and try to come up with a solution.

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.
September 26, 2024

Hi @Veeresh

Any update? As requested in my previous comment, please share a screenshot of the ScriptRunner Behaviour configuration you are using for this.

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events