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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,558,376
Community Members
 
Community Events
184
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
David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 10, 2021

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
David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 12, 2021

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
AUG Leaders

Atlassian Community Events