Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner Validator Issues

Hello All,

I am having some issues with a scripted validator, I am probably being thick and it's right in front of me but I can't seem to get to the bottom of it.

I am looking to validate a Drop Down Custom Field and Two Custom Number Fields.

So far I am using :

 

if ( cfValues['DropDownField']?.value == 'Value' ) {

    if ( cfValues['Number Field 1'] == '0' ) {

        return false

    }

    if ( cfValues['Number Field 2'] == '0') {

        return false

    }

 }

else if .............

else ( return true )

 

I am using the Simple Script Validator.

 

Does anybody have any pointers?

 

 

 

 

 

 

1 answer

1 accepted

1 vote
Answer accepted

Hello, 

If you're using this on a number field, you need to compare your numbers like this:

cfValues['Number Field 2'] == 0

Using single quotes around the number makes it read as a String, where as not putting quotes here will make it read as an integer.

I think everything else looks alright, but if it's still giving you problems please don't hesitate to let me know!

Jenna

Hey Jenna, 

Thanks for the response, I have changed that out in my validation script, however now it is not allowing it through even though the values of both of the number fields are not zero and the select list is == 'Value'.

Are there any gotchas when attempting to query a select list?

Just to make sure as well, the validation field does support if arguments?

I've just been double checking and running some tests.

 

I appears that the first part of the validation is being evaluated, so that:

if ( cfValues['DropDownField']?.value == 'Value' )

Will not allow the transition to occur, but when the field value is not 'Value' it will continue.

It does not seem to go into the if function to evaluate the number fields, it looks like it just stops there.

That is the correct way to query a single select list.

When the select list is not equal to 'Value' it makes sense that  it will return true from the code snippet you have above. If you want it to return as 'true' when 'Value' is selected and neither of your number fields equal '0', you need to explicitly return true at the end of that 'if'. 

I've written a shorter version of what you're doing to test this out and make sure it works:

if(cfValues['Drop Down']?.value == 'Value1'){
if(cfValues['Number'] == 0){
return false
}
return true
}
else{return true}

This will return true for all cases except for when my 'Drop Down' field equals 'Value1' and my 'Number' field equals 0.

If you continue to have issues getting this to work, could you send me the entire script that you're using currently so I can check it?

Jenna

Gotcha, that looks like it's working now, It was the nested return true that I missed off.

I see where I was going wrong there.

Thanks for the help, much appreciated!

@Jenna Davis I am trying to validate a custom number field . ex. I want to validate transition only if the Budget field has a value of "20" or more... how do I achieve this? 

 

Thanks
Ankit

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

272 views 8 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you