Hi,
I have a project with multiple custom issue types
I have 2 custom fields
1. Priority ( select list ) (customfield_10043)
2. Reason for urgency (text field) (customfield_10044)
The above 2 fields are non mandatory and also not present for all issue types
I want to write a scriptrunner script validator on create transition which checks that if Priority ='Critical and urgent' then reason for urgency field should be mandatory.
I wrote something like this
issue.customfield_10043.value=="Critical and Urgent" && issue.customfield_10044.value != ""
the above script doesnt seem to work properly.
When i try to create an issue where these fields are not available, the validator still fires and doesnt allow issue creation
for issues that do have both these fields, validator throws an error if the leave Priority as None (None being auto injected by JIRA as this is not a required field)
I can find how to add a null checking condition in the validator . Also validator tells me that 'Script Validators ONLY use Jira Expressions'
Any help is deeply appreciated.
Thanks !
Hi
I can confirm the answer given by Suhas will not work with ScriptRunner for Jira Cloud as behaviors are only exist inside of ScriptRunner for Jira Server and do not exist inside of ScriptRunner for Jira Cloud as described here.
I can confirm that 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 in a new validator to your workflow.
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 for the issue variable as shown here.
You will notice when reviewing the Jira Expression Framework documentation that it shows you must reference the Priority field by its name of Priority and that it only supports checking values using the name and Id objects as described here.
Also you can see in the Jira Expression Framework documentation page on the Issue Variable how to check custom field values as well as a list of all comparison operators which are supported in the page here.
You will be able to use the Jira Expression Framework documentation pages linked above along with the documentation on the validators feature as reference guides, to see how to construct the validator that you require.
Finally using validators, I can confirm that you can mandate that both the Priority and Jira Expression Framework fields are required but you cannot make the Reason for Urgency field only mandatory when certain fields are selected as the Jira Expression Framework provided by Atlassian does not support this.
I hope this information helps.
Regards,
Kristian
You should use Script Runner Behaviour (its part of Script runner) instead of a workflow validator.
https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html
Try following code
def prio = getFieldById("customfield_XXXX")
def RFU = getFieldById("customfield_XXXX") //Reason for urgency
if (getActionName()=="Create") {
if(prio.value.toString() =~"Critical & Urgent"){
RFU.setRequired(true)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def prio = getFieldById("customfield_XXXX")
def RFU = getFieldById("customfield_XXXX") //Reason for urgency
if (getActionName()=="Create") {
if(prio.value.toString() =~"Critical & Urgent"){
RFU.setRequired(true)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply!
Apologies for the novice question, but from where can I create a behavior? I cannot find any such option even after following link that you posted .
I am on JIRA cloud and using scriptrunner trial
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i am afraid, JIRA cloud does not support behaviors
Validators are also very limited to just JIRA expressions I guess
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry my bad, I didn't see Jira Cloud tag. Yes, Jira cloud doesn't have behaviour.
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.