How to set a custom date field based on selection of priority

I need to set a custom date field to 1 week from today's date if the user chooses "High" for the priority. I need to do it as the user is creating or editing the issue, not post function.

Can I do this with ScriptRunner? If so, does it need to be a behavior or a listener? I tried the listener and it never fires the event.  I am using CustomFieldUpdatedEvent which is obviously wrong cause it never fires the event.

Can someone please direct me? I am totally new to scriptrunner. I searched the site and cannot find how to do this. Below is the logic I tried.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import java.sql.Timestamp

log.debug "in listener " + event.issue

Issue issue = event.issue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Priority"}
if (change) {
//def priority = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Priority")
//if (priority == "High") {
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Delivery Date")
def changeHolder = new DefaultIssueChangeHolder()

// set Delivery Date
def today = new Date()
def result = today + 7
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), result.format("MM/dd/yy")),changeHolder)
//}
}

1 answer

Never mind, solved it.  Added a behaviour below...

import java.sql.Timestamp

def cfPriority = getFieldById("customfield_10628") //priority
def cfDeliveryDate = getFieldById("customfield_11500") //delivery date
log.debug("priority="+cfPriority.getFormValue() + " deliverydate="+cfDeliveryDate.getValue())
if (cfPriority.getFormValue() == "14805") //High
{
cfDeliveryDate.setFormValue(new Date() + 7)
}

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

184 views 1 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you