I have a Select list, Choices Y, N. If user selects Y I unhide a date field and alert them to fill it in.
Now I want a Validator on create issue that Checks if choice is Y, if it is then is date field set and greater than today
My code doesn't work though:-
import com.atlassian.jira.component.ComponentAccessor;
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_39464");
def value = (String)issue.getCustomFieldValue(customField);
//and now simply check
if(value == "Y"){
Date now = new Date()
Date cfDate = new Date(cfValues['Submission to RMGC Date'].getTime())
new Date(now.getYear(), now.getMonth(), now.getDate()).compareTo(cfDate) <= 0
}
else {
result = false
}
What am I doing worng?
Hi Kelvin,
Your script is very close. I see a couple of issues in your script:
import com.atlassian.jira.component.ComponentAccessor
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_39464")
def value = issue.getCustomFieldValue(customField) as String
//and now simply check
if(value == "Y") {
log.debug("checking date")
Date now = new Date()
Date cfDate = new Date(cfValues['Submission to RMGC Date'].getTime())
return new Date(now.getYear(), now.getMonth(), now.getDate()).compareTo(cfDate) < 0
}
else {
true
}
After those changes, the validator works for me:
Thanks for the suggestions. I don't have access to the logs so cant check them.
I made the changes but it still doesn't work. No date, yesterday's date or today's date all work, an issue is created. Even setting false is the choice is not "Y" still works when I select "N".
Is there something I am not uderstanding about validators on Creae issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kelvin,
This is probably a dumb question, but did you remember to publish the workflow after adding this validator?
I'd also make sure you have the right custom field names. Go to the custom fields page and make sure that you have the correct ones.
You might try using getCustomFieldObjectByName in the second line of the script and just put in the name of the custom field, instead of trying to use the ID.
import com.atlassian.jira.component.ComponentAccessor
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Your field name here")
def value = issue.getCustomFieldValue(customField) as String
//and now simply check
if(value == "Y") {
log.debug("checking date")
Date now = new Date()
Date cfDate = new Date(cfValues['Submission to RMGC Date'].getTime())
return new Date(now.getYear(), now.getMonth(), now.getDate()).compareTo(cfDate) < 0
}
else {
true
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes I did publish and I've tried using the field name but same result. I used the cfID as I have 3 other fields I will need to do the same check on.
I'm going to try on my own server tonight which is Jira 7. I'm using Jira 6.4.11 here at work. Also the plugin is v3.1.4....
Thx for your help though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, using ScriptRunner 3.1.4 and JIRA 6 may have something to do with it. I am testing on JIRA 7.4.1 and ScriptRunner 5.0.18. That could be why it works for me and it does not work for you. Perhaps you could convince your workplace to purchase the newest version of ScriptRunner? Kidding, of course... 😉
Let me know how testing on your own server goes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
YHes, tried on my own server running 7.4.x an d the laatest Scriptrunner. It all works.
I've been told process is lower priority now and reporting is important. Like mi;eston e due, missed, etc. Not much point IMHO if they don't complete the date fields... Ho Hum.
Thx again for your help.
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.