Hi
I have a problem with scripted validator - we do have some text custom field which has some default value assigned during creation of the issue (template) and when closing issue I want to check if default value (template) was modified.
Here is the validator which I use - it is working perfectly good when default value (template) is not complex (for example one sentence without enters)
if(!(issue.projectObject.key in ["TEST"])){ return true; } else { if((cfValues['Condition1']?.value in ['Done', 'N/A']) && (!(cfValues['Comment to C1'] in [null, '_Template_']))){ return true; } else { return false; }}
It is checking if project is TEST, then if Condition1 is set to "Done" or "N/A" and then it should check if field "Comment to C1" is not empty and is different than Template.
This is my Template which is used as default value of our text custom field:
_Please adapt this description field according to your needs._
_Examples:_ * first comment
* second comment
Do you have any hints how can I check if this field is not equal to this complex template?
Thanks in advance,
Paulina
Looks like a problem with spacing or newlines.
In your last example Paula you have a space at the end of the lines, but you may well not have that in your default field.
For a test try:
assert template == cfValues['Comment to C1']
It will blow up in a nasty way but the logged message should show you where they differ.
Try to store this template like that:
String template = "_Please adapt this description field according to your needs._ _Examples:_ * first comment * second comment"
And then compare with this variable.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vasiliy Zverev,
Thanks for the reply.
I tried this -> I even used + concatenation operator at the end of each line for having a multi-line string (see code below)
String template; template = String.format("_Please adapt this description field according to your needs._" + "_Examples:_" + "* first comment" + "* second comment"); if(!(issue.projectObject.key in ["TEST"])){ return true; } else { if((cfValues['Condition1']?.value in ['Done', 'N/A']) && (!(cfValues['Comment to C1'] in [null, template]))){ return true; } else { return false; }}
Do you have any idea why it does not work? (I am using simple scripted validator)
Thanks,
Paulina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You miss an "\n" to define new string (see this http://stackoverflow.com/questions/19008970/java-what-does-n-mean). Also pay a lot of attention for spaces. And more: to make validator work you need to create invalidInputException = new InvalidInputException("message") (see https://jamieechlin.atlassian.net/wiki/display/GRV/Validators).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Adding "\n" didint helped and as I am using the simple scripted validator - there is build in message error
String template; template = String.format("_Please adapt this description field according to your needs._ \n"+ "_Examples:_ \n"+ "* All stories done \n"+ "* No critical bug"); if(!(issue.projectObject.key in ["TEST"])){ return true; } else { if((cfValues['Condition1']?.value in ['Done', 'N/A']) && (!(cfValues['Comment to C1'] in [null, template]))){ return true; } else { return false; }}
right now valitator display error when "Comment to C1" is empty (of course if project is TEST and Condition1 is set to "Done" or "N/A") otherwise it accepts everything (also the template and it shouldn't)...
And if template has only one sentence - for example:
String template; template = String.format("_Please adapt this description field according to your needs._ ");
validator works correctly
Paulina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let's define the trouble: how to check that value into a custom field is the same as for template. Is it so? As I can see you add \n and a space, namely " \n", but not "\n". Try this one: ("_Please adapt this description field according to your needs._\n"+ "_Examples:_\n"+ "* All stories done\n"+ "* No critical bug");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, you defined my trouble perfectly:) I copied/pasted your proposition and still it does not work (only when "Comment to C1" is empty - error message is displayed). Spaces which I had were in the template before (I removed them from template in custom field and also pasted your proposition in scripted validator). Maybe there is something else missing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is it correct to say, that it will be enough to find substring "_Please adapt this description field according to your needs._"? Or we need to find exact match?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Sorry for that late answer. I managed to resolved it using such code (I decided to get rid of all new lines in code using replaceAll() when comparing template with field value and it started to work):
String template = '_Please adapt this description field according to your needs._'+"\n"+ '_Examples:_'+"\n"+ '* All stories done'+"\n"+ '* No critical bug'; if(!(issue.projectObject.key in ["TEST"])){ return true; } else { if((cfValues['Condition1']?.value in ['Done', 'N/A']) && (!(cfValues['Comment to C1'] in [null])) && (!(cfValues['Comment to C1'].replaceAll("\n|\r", "") == template.replaceAll("\n|\r", "")))){ return true; } else { return false; }}
Thanks for your support!
Greetings,
Paulina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.