Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

jmwe validator required filed value (condition in groovy)

vsoldatova July 22, 2022

help me please with validation on workflow (create issues)

jmwe conditions

required fileds value must be not empty and !=0

issue.get("customfield_10803")!=0 && issue.get("customfield_10804")!=0
this one should works but it`s not

2 answers

2 accepted

1 vote
Answer accepted
David Fischer
Community Champion
July 22, 2022

Hi @vsoldatova ,

are these Number custom fields? And are you using this script in a "Scripted (Groovy) Validator"?

vsoldatova July 24, 2022

yes, for sure there`re number fields

Screen Shot 2022-07-25 at 17.00.23.png

David Fischer
Community Champion
July 25, 2022

You need to create a Scripted (Groovy) Validator, not a Field Required Validator. Conditional Validation will simply skip validation if the script returns false.

Then the script of the Scripted (Groovy) Validator should be:

issue.get("customfield_10803") && issue.get("customfield_10803") !=0 && issue.get("customfield_10804") && issue.get("customfield_10804") !=0
vsoldatova July 25, 2022

@David Fischer 

yes, thanks! I used two validators. required and Scripted (Groovy) Validator,

vsoldatova July 25, 2022

@David Fischer 
@Florian Bonniec 
could you also help with linked issue type, please!


When test (issue type) created i need :
1. linkedtype  is "tests"
2. linked was possible only with sub-task (issuetype)

David Fischer
Community Champion
July 26, 2022

Hi @vsoldatova ,

I'm sorry but I don't understand what you're trying to achieve. Can you please rephrase?

vsoldatova July 26, 2022

@David Fischer  

how can I write script in the Scripted (Groovy) Validator?
required linked type = "name"
required linked issue type = "name"

 

something like this?
issue.get("issuelinks")equals("tests") && issue.get("issuelinkstype")equals("sub-task") 

 

David Fischer
Community Champion
July 26, 2022

Why don't you simply use a Related Issues Validator? It will allow you to validate this without any scripting

0 votes
Answer accepted
Florian Bonniec
Community Champion
July 22, 2022

Hi @vsoldatova 

First your fields has to be number field, if it's not the case and theyr are text fields, you have to cast them into double or integer.

Also I think you should check if a value exist for your field before.

 

So can you try something like

( issue.get("customfield_10803") && issue.get("customfield_10803") !=0 ) &&

( issue.get("customfield_10804")  && issue.get("customfield_10804") !=0 )

 

Because it my interpret null != 0 as true.

 

Regards

vsoldatova July 24, 2022

yes, for sure there`re number fields.

 

it`s not working as well

( issue.get("customfield_10803") && issue.get("customfield_10803") !=0 ) &&

( issue.get("customfield_10804")  && issue.get("customfield_10804") !=0 )

vsoldatova July 25, 2022

its working. thanks!

Suggest an answer

Log in or Sign up to answer