How to desimple script validator code to ensure that a custom field is not empty when another field is set to a specific value.

Jeff Peters April 16, 2015

Jamie,

 

I am trying to develop simple script validator code to ensure that a custom field is not empty when the Component/s field is set to specific value (Other) while using v2.1.16 of your Script Runner plugin.

The following code is not working:
(issue.components*.name.contains('Other') && (cfValues['Custom Field'].getValue() != null)

Please assist and thank you very much for your services!

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
JamieA
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.
April 17, 2015
! issue.componentObjects*.name.contains('Other') || cfValues['Custom Field']

So... the condition will be true if the components does NOT contain Other, OR, the CF called Custom Field is not empty.

Not tested.

 

Suresh October 19, 2015

I am almost near.Can any help me complete above requirement.

 (! issue.componentObjects*.name.contains('UMB Configuration') || (issue.components*.name.contains('UMB Configuration') && cfValues['Avg File Size'] && cfValues['Avg Daily Volume'])

 

 

0 votes
Jeff Peters April 29, 2015

Meghan,

 

Yes, that is all.  Simple things should be kept simple.

Cheers!

Ryan Gamo June 26, 2015

Jeff, I could not get it to work. I'm adding it to the create issue initial transition. any suggestions?

Jeff Peters June 26, 2015

Hello, Ryan, Are you using custom fields or attribute fields (e.g., Component/s)? What is your current script string? I used the one above on a Create transition. It says that (the Component/s field cannot = Other) or (Component/s = Other and a Custom Field must be populated. I look forward to your reply!

Jeff Peters June 26, 2015

It says that (the Component/s field cannot = Other) or (Component/s = Other and a Custom Field must be populated).

Ryan Gamo June 27, 2015

I found out what I was doing wrong, it was my bad, Correct syntax but incorrect logic. Sorry for the confusion and thanks for the responses.

Suresh October 19, 2015

Hi Jamie, Could you tell me,how can i achieve following in Script validator. Only if -->component = "UMB Configuration" and "Customization Type" = New If the above condition is ture, following two fields are required on transition. "Avg Daily Volume" is require filed. "Avg File Size" is required field Thanks for your help.

JamieA
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.
October 20, 2015

It would be much better if you only ask once rather than three times. An answer will be forthcoming on the question you asked soon.

0 votes
Jeff Peters April 17, 2015

Jamie,

 

You totally rock.  MANY thanks for your prompt and personable response!  

 

The following is what I used successfully:

 

// Check to ensure that if the Component/s is set to "Other" then the Custom Field field must be populated.

(! issue.componentObjects*.name.contains('Other')) || (issue.components*.name.contains('Other') && cfValues['Custom Field'])

 



 

Meghan Mueller April 28, 2015

@Jeff Peters , is this the entirety of your script? I am trying to do something very similar.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events