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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

80 views 0 5
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