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 votes
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
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

330 views 0 1
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