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 not working

I'm trying to restrict a transition when three conditions are true at the same time:

  1. the field "Order Parts" has a value of 'Yes'
  2. the field "Disposition" has a value of EITHER a) 'Rework at OEM & labor $ OEM - (FB)' b) OR 'Rework at OEM - (FR)'
  3. the field "Parts Ordered" has no value

I wrote the following script which is always stopping the transition. It is not allowing the transition to occur when #3 above has a value. For context, I'm using a post function to apply a value of 'Yes' to the field "Parts Ordered" once the sub-task has been closed.

 

if (cfValues['Order Parts']?.getValue() == 'Yes' & (cfValues['Disposition']?.getValue() == 'Rework at OEM & labor $ OEM - (FB)' | cfValues['Disposition']?.getValue() == 'Rework at OEM - (FR)') & cfValues['Parts Ordered'] == null){

return false
}

 

2 answers

1 accepted

0 votes
Answer accepted
Payne Community Leader Jul 18, 2018

You are not returning a value of true if the conditional check fails. Try

if (cfValues['Order Parts']?.getValue() == 'Yes' & (cfValues['Disposition']?.getValue() == 'Rework at OEM & labor $ OEM - (FB)' | cfValues['Disposition']?.getValue() == 'Rework at OEM - (FR)') & cfValues['Parts Ordered'] == null){

return false
}
return true

Perfect. That worked. Thank you!

0 votes

Hello,

Try like this:

if (cfValues['Order Parts']?.getValue() == 'Yes' && (cfValues['Disposition']?.getValue() == 'Rework at OEM & labor $ OEM - (FB)' || cfValues['Disposition']?.getValue() == 'Rework at OEM - (FR)') && cfValues['Parts Ordered'] == null){

return false
}

Hi Alexey,

 

I tried your code and it still wasn't working as expected. I am getting a validator error even when the field "Parts Ordered" has a value of 'Yes'.

Also, I see that your recommended code only changed & to && and | to || but that seems like incorrect login to me. If I understand correctly, by using a double & or double | you are using login that says STOP checking the login as soon as you get to an operator that meets the condition. But I need ALL 3 conditions to be true for the validator to kick in.

Also to be clear, I'm using a Simple Scripted Validator.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Service Desk

Tell us how you've implemented Change Management

Hello Community 👋, I'm a product manager at Atlassian, looking at improving change management capabilities across our products. In particular, we're looking at bridging the gap between Dev & ...

336 views 0 7
Join discussion

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