Hi there. My organization is using Jira Server v7.12.3 and uses the Scriptrunner add-on. Is there a way to set up a Listener that fires an event when one custom field (number) on an issue changes AND another custom field (date) is in a specific range? I have the first part of the condition set up, but not the second.
Here's what I have so far:
def change = changeItems.find {it.field == "Field A"}
if (change) {
def oldValue = change.oldstring
def newValue = change.newstring
}
So, everything is working thus far, but I'm looking to add the below to the condition:
"Field B" > -1d AND "Field B" <= 3d
"Field B" is a custom date field in this case. So, I'd like "Custom Event ABC" only to fire if "Field A" changes AND if "Field B" is in the range of time I specify. Anyone know the right way to script for what I'm trying to do.
Hi @Andrew Zimmerman _Appfire_ , yo could use something like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.fields.CustomField
import org.joda.time.DateTime
import org.joda.time.Days
import org.ofbiz.core.entity.GenericValue
import java.sql.Timestamp
IssueEvent event = event as IssueEvent
MutableIssue issue = event.getIssue()
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
GenericValue changeLogs = event.getChangeLog()
ArrayList<ChangeHistoryItem> changedItems = changeHistoryManager.getAllChangeItems(issue).findAll {
it.changeGroupId == changeLogs.id
}
ChangeHistoryItem change = changedItems.find { it.field == "Field A" }
CustomField cfFieldB = customFieldManager.getCustomFieldObject(11111L) // Field B
Timestamp fielB = issue.getCustomFieldValue(cfFieldB) as Timestamp
Date date = new Date()
DateTime now = new DateTime(new Timestamp(date.getTime()))
DateTime fieldBDate = new DateTime(fielB.getTime())
Integer days = Days.daysBetween(now, fieldBDate).getDays()
if (change && days > -1 && days <= 3) {
//do whatever
}
Thank you @Alejandro Suárez García! In the area where you wrote {{11111L}}, is that where I would input the field name of "Custom Field B"?
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.
Awesome, thanks for all of your help - @Alejandro Suárez García, one more question for now. Do you know if this will work if field B is a Script Field itself? (It's a scripted date field).
Essentially, it adds "Field A" (a number field) to "Field C" (a date field), applies Field A as "business days" and spits out "Field B" as a new scripted date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, if the script field gives you a Date Time, it should work.
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.