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

Attachment Mandatory With ScriptRunner Validator

Sy Hasan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 29, 2024

Hi all,


Bit new to ScriptRunner as I am attempting to build a validator during the transition for when an issue is being created in the workflow on Jira Cloud. I want that when a customer selects specific options from a custom field, they are required to attach and attachment depending on which option is selected. What is the best way to do this? I am attempting to use ScriptRunner but was wondering if anyone may have a clue for what a general script would look like for this?

Also, I am assuming I would need to list option IDs along with of course, the custom field ID. But what's the best way to do so in the script?

In addition, I did find this here stating that this can be a bit challenging from what I've read.

Thanks!

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2024

Hi Sy, 

That article you have linked to is for Jira Data Center and does not apply to Jira Cloud as the  ScriptRunner for Jira Cloud plugin provides Workflow Validators using the Jira Expression Framework as documented in the Atlassian API documentation page located here or in the documentation page located here which explains how to add a new validator to your workflow.

We can confirm that when viewing the Jira Expression Framework API documentation page linked above you can navigate to the Context variables section which shows what variables are provided by this framework that can be used to create the expression.

If you then click on one of the variables, it will show all the properties that can be called on the variable for the expression such as the Issue variable which you can check against.

We can also confirm we have some examples of validators that can be used as a reference guide on the page here as well as in this documentation.

We would recommend using these documentation pages linked above as a reference guide to help create the validator expression that you require.

I hope this information helps.

Regards,

Kristian

Sy Hasan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 30, 2024

Thanks Kristian! So after going through all of this, here's what I have written:

(issue.customfield_10299 &&

[14047, 14035, 14018, 14074, 14049, 14052].includes(issue.customfield_10299.id)) ?

(

issue.customfield_10299.id == 14035 ?

(issue.customfield_10285 && !['AUS', 'DAL', 'HOU', 'STX'].includes(issue.customfield_10285)) ?

issue.attachments.length > 0 :

true :

issue.attachments.length > 0

) :

true

The numbers below customfield_10299, which is a drop down custom field are option IDs (14047 for example). The goal is that when one of the specific drop down option IDs is selected when a ticket is being created, an attachment is required or the issue cannot be created. For customfield_10285, if customfield_10299 has option 14035, an attachment is only required if customfield_10285 is not one of the following exempted written values: AUS, DAL, HOU, STX. Would this make sense? I have tested it, and although it returns as True, the issue is still able to be created without an attachment.

Thanks for your help with this!

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2024
Hi Sy,
I just did a test and came up with an example validator to mandate that an attachment is required when one of a list of specific option values is selected in a single list field.
This example is in the file here, on line 85, and you can use it as a guide to help create the validator you require.
If you need further help modifying this to achieve your use case, I would ask you to create a support ticket with our support team here, who can assist you with this.
I hope this helps.
Regards,
Kristian
Sy Hasan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 30, 2024

Thanks Kristian. I've opened up a ticket for this.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events