Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Tammy Robinson November 28, 2017

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

Suggest an answer

Log in or Sign up to answer
1 vote
Tammy Robinson November 30, 2017

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)
}

TAGS
AUG Leaders

Atlassian Community Events