Hi Dear Colleagues,I need a behaviour script in scriptrunner, which will not allow to set the date greater then 1 year.
Hi @Gor Greyan
Could you provide a little bit more details, i.e. what Date are you referring to?
Is it a custom Date Field?
When do you want the validation to take place? Is it when the Issue is being created, or when the Issue is being transitioned, or when you are editing the Issue?
I am looking forward to your feedback and clarification.
Thank you and Kind regards,Rma
Any updates dear colleagues?
Hi Ram,Yes, my field is Custom Date Field.I want to put that behaviour in the create screen, when choosing the date from that field, it should not allow to select date greater than one year.
Hi @Ram Kumar Aravindakshan _Adaptavist_Did you manage to check my answer?
Sorry, I've been really busy with projects.
For your requirement, you must create a Server-Side Behaviour for the Date field you intend to validate.
Below is a sample working code for your reference:-
import com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.time.TimeCategoryimport groovy.transform.BaseScript@BaseScript FieldBehaviours behavioursdef dateField = getFieldById(fieldChanged)dateField.clearError()if (dateField.value) { def dateFieldValue = dateField.value as Datedef currentDate = new Date(System.currentTimeMillis()) if ( daysBetween(currentDate, dateFieldValue) > 365 ) { dateField.setError('The Date Value Must Not Exceed 1 Year') }}static def daysBetween(def startDate, def endDate) { use(TimeCategory) { def duration = endDate - startDatereturn duration.days}}
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:-
Please note, in the screenshot above, the editor is showing a few red lines. These are not coding errors, but are static type checks. In other words, the code works and is able to return the expected result.
I hope this helps to answer your question. Thank you and Kind regards,Ram
It looks like you're new here. Sign in or register to get started.