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!
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
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Kristian. I've opened up a ticket for this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.