The following script is calling when the value of CustomField1 is 'No' also. How to restrict that?
cfValues['CustomField1']?.value == 'Yes' && cfValues['Custom Field2']
I want to check if CustomField1 value is yes and CustomField2 is not null
actually following should work
cfValues['Downtime Requirement']?.value == 'Yes' && cfValues['Downtime Duration']
can you check space in options of Downtime requirement field or may be spaces added in customfield names, some times this may be root cause
the following code we are using in our java base validator, you can convert/modify to groovy
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.customfields.option.Option; CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager(); CustomField downtimeRequirement = cfm.getCustomFieldObjectByName("Downtime Requirement"); CustomField downtimeDuration = cfm.getCustomFieldObjectByName("Downtime Duration"); Option drOption = (Option) issue.getCustomFieldValue(downtimeRequirement); def ddValue = issue.getCustomFieldValue(downtimeDuration); if(drOption != null && drOption.getValue == 'Yes' && ddValue == null ){ //throw error message }
Hi Prasad,
Thank you for your comment.
I will test the condition and update. I have one question. If I call a groovy script file instead of a condition, how can i show a validation error message(like the one showed on my screenshot)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Prasad,
It is working now :)
if(drOption != null && drOption.getValue() == 'Yes' && ddValue == null ){
invalidInputException = new InvalidInputException (downtimeDuration.getId(),"Please select Downtime Duration")
} else if(drOption != null && drOption.getValue() == 'No' && ddValue != null ){
invalidInputException = new InvalidInputException (downtimeDuration.getId(),"Downtime Requirement should be 'Yes' for selecting Downtime Duration")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just posting something related to here so someone could save his/her time.
Scenario: There are two custom date fields, cfA, cfB and one custom radio button group field cfC with options None/Approve/Reject . On a post function transition, I need to copy the value of cfA to cfB if ONLY cfC has its option selected = Approve.
The scriptrunner provides copy field to another with an if condition evaluating to true . Instead of getting the Option first and then checking if its not null and then getting its value (like the code above), this direct call on the custom radio button group field and checking if it equal to Approve worked fine.
issue.get("customfield_XXXXX") == "Approve" //cfC field
There was no need to use getAt(), getValue() etc..for groovy script here(maybe I got scriptrunner's latest version?)
This worked fine with JiRA 5.2+/Scriptrunner 2.1.15 and JIRA 6+/Scriptrunner 3.0.6
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, it sounds like you are using JIRA Misc Workflow Utilities.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Jamie,
It is working now with groovy script instead of simple script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You've just got to think through the logic. Don't try to do it in a one-line...
if (field) { check other field } else { other field should be empty }
etc
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
xor operator also failed. I tested but none of the combination is success though I have set the condition in the same way you suggested.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Look into ^, which is the xor operator.
You want either Yes and a duration value set, or No and no duration value.
So it should be
Downtme Requirement == No xor Downtime Duration
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
The script is !cfValues['Downtime Duration'] && cfValues['Downtime Requirement']?.value == 'No'
Below you can see when i select the radio option Yes, I want to allow the transition to create issue with a downtime duration, but in the screenshot it is showing with error message which is incorrect. Please suggest what is wrong in the above script..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Jamie,
This is behaving weired. I removed the assert and checked the condition. I am totally confused.. Sometimes with Yes and Sometimes with No I am getting the error message.. :(
I understood from my condition that the whole issue is due to incorrect null checking. Could you please let me know how to check null using script?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure what you're expecting here - I can see that that evals to false. I can't even remember what the original problem was.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What I want is the validator should show an error message when the value of customfield1 is 'Yes' and when the value of customfield2 is null but it is showing the error message when the value of customfield1 is 'No' also and when the value of customfield2 is null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry. I just added.. Could you please check the question now?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's not showing, can you add it to the question or something, or maybe upload it somewhere else.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please find the screeenshot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> Any update
Jesus... I do sleep you know.
Can you paste a screenshot of condition tester. I don't believe this eval'd to true.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
Any update please? I am not getting how to handle the null field on this condition. Could you please advise??
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I checked with assert but how can we evaluate with null? If no value is selected for "Downtime Duration", the value stored is null but it is not evaluating. Could you please suggest on how to handle null?
assert cfValues['Downtime Requirement']?.value == 'Yes' && cfValues['Downtime Duration'] == null
| | | | |
| No No false false
[Accept ID:null, Affects Build:null, Approved Date:null, Approver :null, Area:[Product Specific], Browser:null, CC List:null, Change Request Category:[null:Production Servers, 1:Software Change], Change Request Plan:null, Compiler:[], Completed By:null, Completed Date:null, Confirmed Date:null, Confirmer:null, Confirmer Build:null, Confirmer Version:null, Database:null, Downtime Duration:null,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try using asserts in admin->built-in scripts->condition tester. See https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-PowerAssertions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the confusion. Just to be more clear on AAC, I have referred "Downtime Requirement" as CustomField1.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But you've used a field name of CustomField1, when you said the field name is Downtime Requirement...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
The line which I have posted is the only condition. I just wanted to check if the selected radio button option of CustomField1 is 'Yes', then it is manadatory to choose CustomField2 radio. I have used "Script Validator" and added the condition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Post the code you're actually using...
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.