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,
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 @PD 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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.