Hi all
Once again I turn to the community to see if the nightmare that is Groovy scripting has a solution for this requirement :D
Since there's no JQL issue functions that can compare a date field with a date attribute of an Insight object, I'm wondering if anyone has anything that will accomplish this.
I'm looking to have a condition on two transitions out of our CAB Approval status, one to the Awaiting Implementation status and another to the Change Freeze Approval status.
Based on Scheduled Start custom field being < Change Freeze Start Insight object attribute or > Change Freeze End Insight attribute.
Any ideas? thanks
One person's nightmare....
Here I just whipped this up (took about 15 minutes)
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
@WithPlugin('com.riadalabs.jira.plugins.insight')
@PluginModule ObjectFacade objectFacade
def dateFieldName = 'Scheduled Start'
def insightFieldName = 'unknown'
def startAttribute = 'Change Freeze Start'
def endAttribute = 'Change Freeze End'
def dateValue = cfValues[dateFieldName] as Date
def insightObjValue = cfValues[insightFieldName] as List<ObjectBean>
if(!dateValue || !insightObjValue){
return //missing some info to compare
}
//insight custom field always return an array even if they only allow single value. Assume there is only one
insightObjValue = insightObjValue.first()
def freezeStartAttr = objectFacade.loadObjectAttributeBean(insightObjValue.id, startAttribute)
def freezeEndAttr = objectFacade.loadObjectAttributeBean(insightObjValue.id, endAttribute)
def freezeStart = freezeStartAttr?.objectAttributeValueBeans && freezeStartAttr.objectAttributeValueBeans[0].dateValue
def freezeEnd = freezeEndAttr?.objectAttributeValueBeans && freezeEndAttr.objectAttributeValueBeans[0].dateValue
if(dateValue < freezeStart){
return false
}
if(dateValue > freezeEnd){
return false
}
return true
Other than adjusting the last 7 lines according to your actual requirement, this should get you close.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Testing results, seems to have a problem with the cfvalue
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
@WithPlugin('com.riadalabs.jira.plugins.insight')
@PluginModule ObjectFacade objectFacade
def dateFieldName = 'Scheduled Start'
def insightFieldName = 'Change Freeze Status'
def startAttribute = 'Change Freeze Start'
def endAttribute = 'Change Freeze End'
def dateValue = cfValues[dateFieldName] as Date
def insightObjValue = cfValues[insightFieldName] as List<ObjectBean>
if(!dateValue || !insightObjValue){
return //missing some info to compare
}
//insight custom field always return an array even if they only allow single value. Assume there is only one
insightObjValue = insightObjValue.first()
def freezeStartAttr = objectFacade.loadObjectAttributeBean(insightObjValue.id, startAttribute)
def freezeEndAttr = objectFacade.loadObjectAttributeBean(insightObjValue.id, endAttribute)
def freezeStart = freezeStartAttr?.objectAttributeValueBeans && freezeStartAttr.objectAttributeValueBeans[0].dateValue
def freezeEnd = freezeEndAttr?.objectAttributeValueBeans && freezeEndAttr.objectAttributeValueBeans[0].dateValue
if(dateValue < freezeStart){
return false
}
if(dateValue > freezeEnd){
return false
}
return true
There was an error during the execution of your script against issue CIT-836
groovy.lang.MissingPropertyException: No such property: cfValues for class: script_e508d908ba07d40a9f5832eac77c6894
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:65) org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51) org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309) script_e508d908ba07d40a9f5832eac77c6894.run(script_e508d908ba07d40a9f5832eac77c6894.groovy:15)
The Scheduled start definitely has a value, but it may be because it's a Date time picker field, it would be nice if it could actually work with a Datetime Insight value and a Date Time field as I know these CAB guys have things they'd want to kick in at say 8pm and end at 7am.
Additionally, could you add a clause for the Scheduled End field and the scheduled end not being during the change freeze too?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have to use "simple scripted condition" to be able to leverage the cfValues.
Here is the same script with both the start and end date.
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
@WithPlugin('com.riadalabs.jira.plugins.insight')
@PluginModule ObjectFacade objectFacade
def startDateName = 'Scheduled Start'
def endDateName = 'Scheduled End'
def insightFieldName = 'Change Freeze Status'
def startAttribute = 'Change Freeze Start'
def endAttribute = 'Change Freeze End'
def startDateValue = cfValues[startDateName] as Date
def endDateValue = cfValues[endDateName] as Date
def insightObjValue = cfValues[insightFieldName] as List<ObjectBean>
if(!startDateValue || !endDateValue || !insightObjValue){
return false//missing some info to compare
}
//insight custom field always return an array even if they only allow single value. Assume there is only one
insightObjValue = insightObjValue.first()
def freezeStartAttr = objectFacade.loadObjectAttributeBean(insightObjValue.id, startAttribute)
def freezeEndAttr = objectFacade.loadObjectAttributeBean(insightObjValue.id, endAttribute)
def freezeStart = freezeStartAttr?.objectAttributeValueBeans && freezeStartAttr.objectAttributeValueBeans[0].dateValue
def freezeEnd = freezeEndAttr?.objectAttributeValueBeans && freezeEndAttr.objectAttributeValueBeans[0].dateValue
if(startDateValue <= freezeStart || startDateValue >= freezeEnd){
//start date is outside freeze window
return false
}
if(endDateValue <= freezeStart || endDateValue >= freezeEnd){
//end date is outside freeze window
return false
}
return true
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.