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 Join to answer
Community showcase
Emilee Spencer
Published Friday in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

58 views 0 3
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot