ScriptRunner validator - url field contains ".pdf"

Jennifer Maurer
Contributor
November 13, 2024

Using Jira Data Center 9.4.15

I have a custom field called "Report PDF URL". I have a workflow transition step where I'd like to validate that the url entered into that custom field contains ".pdf". 

I found this previous post: 

https://community.atlassian.com/t5/Jira-questions/URL-Validation-for-Free-Text-field/qaq-p/1987373

and the suggested scriptrunner: 

cfValues['URL Field Name'] ==~ /^((?:https?:\/\/)?(?:www\.)?[-\w@:%.+~#=]{2,256}\.[a-z]{2,6}\b[-\w@:%+.~#?&\/=]*|)$/

...but I'm unclear how to modify this for my use case.

Please help, thanks.

2 answers

0 votes
Bobby Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2024

Hi @Jennifer Maurer ,

It looks you are right, our regex validator only supports text fields at the minute. I will feed this back to the team, however in the meantime you can achieve this with the Simple Scripted Validator with the following script: 

def value = issue.getCustomFieldValue('Custom Url Field') // This needs to be your field name
def pattern = /.*\.pdf$/

boolean match = value ==~ pattern

return match


Could you give this a go and let me know how you get on?

Kind regards, 

Bobby

0 votes
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 13, 2024

Hi @Jennifer Maurer 

 

Could you try this regex ?

^https?:\/\/.*\.pdf$

Regards

Jennifer Maurer
Contributor
November 13, 2024

it looks like the regex validator only works on text fields, this is a url field...

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 13, 2024

You do not have the Regular Expression Check validator ? It works on my side.

 

Regards

Bobby Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2024

@Florian Bonniec , 

Ahh, this confused me. This question was tagged for Cloud, but @Jennifer Maurer is using DC as mentioned in her question. 

I will repost what I linked: 

On DC, Scriptrunner's regular expression validator only supports: 

 

  • System fields - Description, Environment, and Summary
  • Custom fields - Text Field (single line) and Text Field (multi-line)

 

https://docs.adaptavist.com/sr4js/latest/features/workflows/validators/regular-expression-validator

You can still do this check, just need to write the script. 

Sorry for the confusion!

Kind regards, 

Bobby

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events