Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,994
Community Members
 
Community Events
165
Community Groups

How To Conditionally Enforce REGEX Validation Depending on A Custom Field Value

Hi there.  Using either ScriptRunner / JSU / JMWE, is there a way to satisfy the following conditions:

Fields:

  • *File Source - Single Select field.
    • Google
    • Yahoo
    • Bing
  • *File Source URL - Single text field

Conditions:

  • File Source URL will will need to begin to match the beginning depending what File Source value is selected (e.g https://google.com)
  • File Source URL will need to end to match the ending in pdf

Examples:

We've been able to make some progress to check use ScriptRunner's Regular expression validator [ScriptRunner] to be able to make something like this happen with the following:

^https:\/\/google.com\/.*.pdf

 However, I struggle to expand the script above to interact with another field.  Any insights is appreciated!

1 answer

0 votes

Hi @Ricky Wang Lin 

with JMWE, you could use a Scripted (Groovy) Validator with code like this:

switch (issue.get("File Source")) {
case "Google": return issue.get("File Source URL") ==~ /^https:\/\/google.com\/.*.pdf/
case "Yahoo": return issue.get("File Source URL") ==~ /^https:\/\/yahoo.com\/.*.pdf/
default: return true //no check if another source
}

Hi David.  Thank you the response!  Is it also possible to conditionally display a different error message for each one (depending on the File Source value)?

Example:

  • If someone enters "www.google.com" instead of "https:google.com",  display error message 1
  • If someone enters "www.yahoo.com" instead of "https:yahoo.com",  display error message 2

Absolutely! Instead of returning a boolean value (true/false), you can return a String that will be the error message:

switch (issue.get("File Source")) {
case "Google": return issue.get("File Source URL") ==~ /^https:\/\/google.com\/.*.pdf/ ?: "The URL is not from Google"
case "Yahoo": return issue.get("File Source URL") ==~ /^https:\/\/yahoo.com\/.*.pdf/ ?: "The URL is not from Yahoo"
default: return true //no check if another source
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

335 views 2 7
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