Need to Throw An Error When Expected Words Missing From Jira Text Field

Kay February 17, 2020

Hello Community, 

Can you please provide some ideas or maybe snippet of code to throw an error when users do not enter mandatory words in a Jira text field. 

Example: I have a text field, called "Action Plan". When a user creates a ticket and types words which do not include the same word "Notify" two times at the beginning and the end of the text field or in any orders, it will give them an error " Please include word "notify" at the start and the end of your action plan". I would like to make sure the same word needed to be mentioned twice in the same field. Should I use behavior or Automation in Jira?  Please advise. Thank you tons in advance for your help. 

Kay, 

2 answers

1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 13, 2020

You know you've made is as a community answerer when you are mentioned by name :)

Hi @Kay 

You can use either behavior with the setError("error text") method or use a workflow validator script.

The advantage of the behaviour is that it will run on edits as well as transitions.

The disadvantages of behavior are that if users make changes via the REST API, your validation will not take place and if they customize their view screen and hide the field, your validation will not take place.

Now if you are looking for how to check if the word 'notify' is present, regular expression is probably the way to go. But the exact expression will depend on how flexible you can be in the rule.

Here is a code snippet on how to test your text against an expression:

def text = """
notify some
text notify
"""

def matcher = text =~ /(?si)^\s*notify.*notify\s*$/
matcher.matches()

This will return true/false if the string matches the pattern.

I'm really not all that good at regular expression. But you can test various options using regex101.

Here is the expression I used in the code above: https://regex101.com/r/tUcymT/3

This will be true if the string starts with "notify" (excluding any preceding whitespace characters) and ends with notify with anything in between. If you want to allow other string at the end : notify{anythingelse}notify{anythingelse} then you can try this pattern:

/(?si)^\s*notify.*notify.*$/

0 votes
Kay March 13, 2020

Hello @Peter-Dave Sheehan

You have helped me before with very good answers and suggestion. If you have a chance, can you please take a look and help with this?

Kay, 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events