Hello Community,
Disclosure, I'm not a coder and have limited experience with Scriptrunner. Having said that, I'd like to create a validator on the create transition in a new Service Desk project that checks to see if at least one of two fields is populated. I found a previous thread that mentioned this might work but it does not for me.
cfValues['Budget Department'] || cfValues['Project\Program ID']
Any help is appreciated.
Thanks, Michael J
So... I made an error when testing. First, I was trying to use the 'Scripted (Groovy) Validator (JMWE add-on)' instead of the Simple Scripted Validator. Although, once I realized that, I still could not get one of the above solutions to work. Here is the code that worked for me. Maybe it will help someone else.
cfValues['Budget Department'] != null || cfValues['Project\\Program ID'] != null
This is currently working for a mixed set of a single select and a text box but will eventually be two single select fields.
Hello @Michael Johnson
Can you try this (change the name of my select list with name of your custom field)
if (cfValues['My Select List']?.value || cfValues['My Select List']?.value ) {
return true;
} else {
return false;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tarun,
Thank for your help, the code you provided returned the error below when I tried to create an issue with it in place.
if (cfValues['Budget Department']?.value || cfValues['Project\\Program ID']?.value ) {
return true;
} else {
return false;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Michael,
Can you try this:
cfValues['Budget Department'] || cfValues['Project\Program ID']!= ' '
If it's worked you will have to populate the two customfield to go forward
Hope this helps
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mohamed,
Thanks for your reply but I don't need to have both fields populated, At least one needs to be populated but not both at the same time.
Best, Michael J
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry Michael,
I read too fast
I'm not a groovy coder but you can try this:
if (cfValues['Budget Department']!='' && cfValues['Project\Program ID']==''){
return true
}
else if (cfValues['Budget Department']=='' && cfValues['Project\Program ID']!=''){
return true
}
else return false
Maybe who will have an error with the \ character.
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mohamed,
Here's the code I tried and it gave the error below.
if (cfValues['Budget Department']!='' && cfValues['Project\\Program ID']==''){
return true
}
else if (cfValues['Budget Department']=='' && cfValues['Project\\Program ID']!=''){
return true
}
else return false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.