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)
//}
}
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.