Validate against Custom Date Field and another Custom Field

Kristjan Geir Mathiesen - Origo January 5, 2016

Hi all smile

Ok, I need to perform a validation in a transistion. I´ve got two Custom Fields:

"FBD" which is a date picker

"Probability" which is a select list (single choice)

This is the logic I am looking for:

If "Probability" = 100%, then I want to validate that "FBD" is not empty (i.e. "FBD" has to have a date).

If  "Probability" = 0%, then "FBD" can be empty and in fact, I don´t want to check it at all.

I am going to use Script Workflow Function and if I use this:

cfValues['FBD']

then FBD is always required regardless of the value in "Probability" (since it´s not checked). So I tried OR-ing like this:

(cfValues['Probability']?.value == '0%') || (cfValues['Probability']?.value == '100%' && cfValues['FBD'])

But it doesn´t work :/  Any ideas? 

Thanks guys.

5 answers

1 accepted

1 vote
Answer accepted
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 18, 2016

Hi Kristjan

Apparently the cfValues for date doesn't work as expected. Try to retrieve the value using the customFieldManager, in your case:

import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("FBD")
def fbdValue = issue.getCustomFieldValue(customField)
(cfValues['Probability']?.value == '0%') || 
    (cfValues['Probability']?.value == '100%' && fbdValue)

Hope that helps

Kristjan Geir Mathiesen - Origo January 20, 2016

Thanks Thanos. Weird how date doesn´t work as expected. Now wonder I got nowhere. You rock! This worked. Thanks SO very much for your help. Kudos to you smile

0 votes
Kristjan Geir Mathiesen - Origo January 7, 2016

Thanks Steven.

0 votes
Steven F Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 6, 2016

That is ScriptRunner yes. I'll label your post with ScriptRunner so Adaptavist may find it easier. If I can assist I will post an Answer.

0 votes
Kristjan Geir Mathiesen - Origo January 6, 2016

Hi Steven.

To be honest, I am not totally sure. I think it´s Groovy though. Here is a picture of it with an example from the manufacturer:

script.JPG

 Thanks.

0 votes
Steven F Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 5, 2016

What scripting add-on is this?

Suggest an answer

Log in or Sign up to answer