Automatically Update Field "A" With Date/Time When Field "B" is Set to "Yes"

I have two custom fields: "A" and "B". I would like to know if there's a way to automate field "A" so when field "B" is set to "Yes", field "A" is automatically filled with the "date and time" when the field "B" was set to "Yes".

Right now I'm able to do that but I'm using "Behaviors" and, every time I edit the issue, it updates the field with the current date and time again.

3 answers

This is the script I'm using:

import com.onresolve.jira.groovy.user.FormField

FormField automated = getFieldById(fieldChanged)
FormField automatedDate = getFieldByName("Automated Date")
String automatedValue = automated.getValue()
String automatedDateValue = automatedDate.getValue()
Date now = new Date()
String nowString = now.format('dd/MMM/yy hh:mm a')

if (automatedValue == "Yes") {
    automatedDate.setFormValue(nowString)
}
else {
    automatedDate.setFormValue("")
}

 

Thsi is the script I'm using now:

 

import com.onresolve.jira.groovy.user.FormField

FormField automated = getFieldById(fieldChanged)
FormField automatedDate = getFieldByName("Automated Date")
String automatedValue = automated.getValue()
String automatedDateValue = automatedDate.getValue()
Date now = new Date()
String nowString = now.format('dd/MMM/yy hh:mm a')

if (automatedValue == "Yes") {
    automatedDate.setFormValue(nowString)
}
else {
    automatedDate.setFormValue("")
}

I tried to modify the "if" to something like that:

if (automatedValue == "Yes" && automatedDateValue == "")

but then the "Automated" field is blank all the time.

 

0 vote
Andreas Knecht Community Champion Jul 11, 2017

Hi Fabio,

I am one of the founders of Code Barrel and we make Automation for JIRA.

It should be fairly easy to achieve this with Automation for JIRA. You could setup an Automation rule like this:

  • Trigger: Field value changed (with field A)
  • Condition: Compare {{toString}} to 'Yes'
  • Action: Edit issue field and set the date field you want to set. You can use the {{now}} date smart value (see working with dates)

The field value changed trigger will only run the rule when the particular field A is edited.  The condition will make sure the issue is only edited when the field was set to 'Yes'.

Cheers,
  Andreas

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 Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

112 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