Forums

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

Using Scriptrunner how do you validate if one field or the other is null?

Matt Noe
Contributor
April 12, 2022

I'm using a ScriptRunner Workflow Validator to confirm that two fields are not both null.

I'm using the following:

issue.customfield_10178.value != null || issue.customfield_10284 != null

If I evaluate either side of the expression, I get the result I expect, however when using the "or" I get the following error:

Evaluation failed: "issue.customfield_10178.value" - Unrecognized property of `issue.customfield_10178`: "value" ('value'). Type null does not have any properties

Is there a better way to evaluate that my two fields aren't both null?  Both fields are single pickers.

1 answer

1 accepted

0 votes
Answer accepted
Matt Noe
Contributor
April 12, 2022

I found my error.  I had an erroneous '.value' behind my first custom field.

Gregory Kremer
Contributor
January 31, 2023

@Matt Noe The expression

issue.customfield_10178.value != null || issue.customfield_10284 != null

means that both fields need to have values (not empty). How does your expression for the "or" option look like?  My main concern here is to make sure that if field#1 is empty then field #2 should not. But if field one is not empty I don't care much about field #2. I'd greatly appreciate your prompt reply.

Matt Noe
Contributor
January 31, 2023

Hi @Gregory Kremer  The || stands for "or" so it validates that at least one of the two fields are populated (not equal to null), or both can be populated.  If both are empty, then the code doesn't proceed.  

The evaluation would look something like this:

  • Value field 1 = null, value field 2 = null
    • Error
  • Value field 1 not null, value field 2 = null
    • Pass
  • Value field 1 = null, value field 2 not null
    • Pass
  • Value field 1 not null, value field 2 not null
    • Pass

I'm currently using this to validate on a transition that both fields aren't left blank.

Hope this helps

Gregory Kremer
Contributor
January 31, 2023

@Matt Noe Thanks Mat. It worked. Appreciate your assistance.

Like Matt Noe likes this

Suggest an answer

Log in or Sign up to answer