Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JIRA Automation Rules to check if a value of a field does not exist on the same field of other ticke

James Park
Contributor
January 11, 2023

Hello,

Before a ticket is closed, I would like to make sure that a value of a text field in the current ticket is unique value with the same fields in all other tickets.

Is there a way to do this using automation rules?

 

2 answers

1 accepted

1 vote
Answer accepted
Trudy Claspill
Community Champion
January 11, 2023

Hello @James Park 

Are you looking at the entire contents of the text field as a whole, or just some part of the text field? Does a difference in the case of the text make it a unique value?

Can you provide more context on the problem you are trying to solve? Why are you using a text field to try to track a value and ensure that value is unique across all tickets? How does the value of that field get set?

How many issues are going to need to be reviewed? Tens of issues? Hundreds of issues? Thousands of issues? How frequently are new issues created? How often is the field updated?

You could create an Automation Rule that is triggered by a change of value on that text field. You could add to the rule a Lookup Issues action to look for issue based on a JQL statement that searches for issues where the specified text field has the same contents as the text field of the issue that transitioned. You could then check if results of the Lookup Issues action was more than 1 issue using an Advanced Compare.

You would then need to have the rule take some action when the results have more than 1 issue. The issue could be sending an email to somebody to alert them of the issues with duplicated values.

If it is possible to change the field value during the transition to Closed, this would not prevent the transition.

James Park
Contributor
January 11, 2023

Q1-As a whole. Case does not make difference.

Q2-Only reason for using the text field is that it can be whatever the creator puts it. Yes, I am using a text value to track.

Q3-the issues can be about few hundreds. I am not sure how to use "Lookup Issues action"

I am not sure how to do this... It seems to make sense though.

"You could create an Automation Rule that is triggered by a change of value on that text field. You could add to the rule a Lookup Issues action to look for issue based on a JQL statement that searches for issues where the specified text field has the same contents as the text field of the issue that transitioned. You could then check if results of the Lookup Issues action was more than 1 issue using an Advanced Compare."

 

Example:

I have a field called "MFR Code". It has the value "B6".

Before I can close this ticket with the value B6, I would like the rule to check if the value has been used in any other tickets in the issue type "Manufacturing Code Request" because I do not want to create a new ticket with the value that had been used for another MFR.

Trudy Claspill
Community Champion
January 11, 2023

You can find documentation for all the available Actions for Automation Rules here:

https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/

The JQL statement you use in this action would use a smart value for the MFR Code field for the criteria, thus:

type="Manufacturing Code Request" and "MFR Code" ~ {{triggerIssue.MFR Code}} and key != {{triggerIssue.key}}

The last bit is to exclude the triggering issue from the results.

To check the number of results returned you would use an Advanced Compare thus:

Screen Shot 2023-01-11 at 4.55.31 PM.png

 

One more question - do you expect that users will add that includes spaces or non-alphanumeric characters?

James Park
Contributor
January 12, 2023

Oh my my!

This worked. 

 

Used "Related issues condition"

issuetype="Manufacturing Code Request" and "MFR Code" ~ {{triggerIssue.MFR Code}} and key != {{triggerIssue.key}}

 

Thank you so much.

1 vote
Mark Segall
Community Champion
January 11, 2023

Hi @James Park 

You can have automation help with this, but automation doesn't provide validation.  You could take this approach:

  • Use a custom text field as a flag (keep it hidden from the screen)
  • Add a workflow validator on the transition to closed that the custom field cannot be empty
  • Add a status that serves as a staging point for automation to determine whether the issue can be resolved or kicked back

Use an automation rule like this:

  • Field1 = Your unique field
  • Field2 = The custom field we're using as a flag

 

  • TRIGGER:  Issue Transitioned YourNewStatus
  • ACTION: Lookup Issues
    • Field1 ~ "{{issue.Field1}}
  • IF CONDITION: Advanced
    • {{lookupIssues.size}}
      Greater Than
      0
    • ACTION: Transition Issue Back
  • ELSE
    • ACTION: Edit Issue (Field2)
      • Add whatever you want.  This will satisfy the workflow validator
    • ACTION: Transition Issue to Closed

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events