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

Fabio S July 11, 2017

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

0 votes
andreas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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

0 votes
Fabio S July 11, 2017

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
Fabio S July 11, 2017

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("")
}

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events