Hi All,
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?
Thanks,
Anand
@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:
import org.apache.log4j.Category
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.opensymphony.workflow.InvalidInputException
// 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()
entered_date.setTime value
if (entered_date.get(Calendar.MONTH) == now.get(Calendar.MONTH) && entered_date.get(Calendar.YEAR) == now.get(Calendar.YEAR))
return;
if (now.before(entered_date))
return;
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
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.
Thanks,
Anand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried renaming your variable, as specified in the warning?
"Please choose a different name for variable "componentManager": @ Line 13, Column 18."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.