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

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

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
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

142 views 1 12
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