Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Listener - Condition for CustomField change AND custom date field in range

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:

  • I'm using Scriptrunner's "Fires an event when condition is true" Listener
  • Set to run in Project "PROJECT ABC"
  • Event Trigger: "Issue Updated"
  • Condition:
    • def change = changeItems.find {it.field == "Field A"}
      if (change) {
      def oldValue = change.oldstring
      def newValue = change.newstring
      }
  • Event to fire: "Custom Event ABC"

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.

1 answer

Hi @Andrew Zimmerman , 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 _Tecnofor_! In the area where you wrote {{11111L}}, is that where I would input the field name of "Custom Field B"?

Hi @Andrew Zimmerman , you have to input the ID of the field B

Awesome, thanks for all of your help - @Alejandro Suárez _Tecnofor_, 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.

Yes, if the script field gives you a Date Time, it should work.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

52 views 0 2
Read article

Community Events

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

Events near you