Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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.*$/

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
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

260 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you