We have two date fields, i.e. "From" and "To". We want to implement following business logic on both fields:
1) Dates shouldn't be allowed in the past, better if we only allow date/time selection from now and any date/time in future
2) "To" date cannot be less than "From" date.
I have simulated an "Edit" transition that gives a workflow screen and I intend to use a workflow validator. We have Scriptrunner licensed. I referred to following pages, however I couldn't get a simple/custom script validator to work:
Anyone worked on similar solution and has a script that would work for the criteria above?
@Trudy Claspill thank you for looking into the issue.
After the field has been associated with the context and screen, past date are still being allowed on the "From" date/time picker field.
My script is as follows:
// replace 10000 by number of date time custom field that must be validated
def fieldname = "customfield_16200"
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField field = customFieldManager.getCustomFieldObject(fieldname)
Date value = issue.getCustomFieldValue(field)
Calendar now = Calendar.getInstance()
Calendar entered_date = Calendar.getInstance()
if (entered_date.get(Calendar.MONTH) == now.get(Calendar.MONTH) && entered_date.get(Calendar.YEAR) == now.get(Calendar.YEAR))
def invalidInputException = new InvalidInputException("Entered date is invalid! From date must be set in future")
It throws a warning with a yellow triangle as follows:
Variable "componentManager" masks a binding variable of the same name. Please choose a different name for variable "componentManager": @ Line 13, Column 18.
Application logs shows:
2021-03-18 09:44:54,066-0400 http-nio-8080-exec-17 ERROR Anand.Dandikar 584x21519x1 9hhrid 10.3.205.167,0:0:0:0:0:0:0:1 /secure/AjaxIssueEditAction!default.jspa [c.atlassian.velocity.DefaultVelocityManager] MethodInvocationException occurred getting message body from Velocity: java.lang.NullPointerException
When previewing the script with a test issuekey, I get:
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.component.pico.ComponentManager.getCustomFieldManager() is applicable for argument types: () values:  at Script31.run(Script31.groovy:14)
JSU Automation Suite has data expression compare, however since we have already licensed Scriptrunner, we would prefer to implement this via a script validator. Please suggest.
If you already heard about Smart Commits in Bitbucket, know that you just stumbled upon something even better (and smarter!): Genius Commits by Better DevOps Automation for Jira Data Center (+ Server...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events