I have a CustomField that is of a multiline Wiki rendered type. I want to validate that the default value (set in a project scope on the field) has been changed/edited/added to to allow a specific transition. how can I do this using a ScriptRunner validator, or other ScriptRunner utility?
Hello,
You would just need to set up a simple scripted validator on the transition to do this.
Something like this within the condition should work:
cfValues["Your Field's Name"] != 'The Default Value'
As long as the default value is the same between different issues, this should work fine. You should also be able to set up a behaviour on your workflow transition to do something similar if you'd prefer to do that.
Hope this helps! Let me know if you have any questions.
Regards,
Jenna
I did try that, but it always resulted in a false for some reason. I'm wondering if it is because there is wiki markup in the default value, or if I am perhaps not handling multiple lines/line breaks correctly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You'll have to include the wiki markup characters (like, h1 or {quote}) inside of your default value.
The newline characters are likely also throwing it off, you might be able to use something like:
System.getProperty("line.separator")
To make sure you're getting the correct newline charater. I have not tested this though. You'll just have to play around with the formating of the default value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is where I am at:
ScriptRunner workflow function - Simple scripted validator (condition apply).
import org.apache.log4j.Logger import org.apache.log4j.Level def log = Logger.getLogger("com.acme.CreateSubtask") log.setLevel(Level.DEBUG) String defaultText = "h1. Change Plan" + System.getProperty("line.separator") + "----" + System.getProperty("line.separator") + "||Step||Estimated start time||Duration||Activity||Implementer||Expected Result||Risk Level||" + System.getProperty("line.separator") + "| | | | | | | |" + System.getProperty("line.separator") + "----" + System.getProperty("line.separator") + "h1. Rollback Plan" + System.getProperty("line.separator") + "----" + System.getProperty("line.separator") + "<insert plan text here>"
String currentText = cfValues["Change Plan"] if(currentText != defaultText) { log.debug "True" log.debug currentText log.debug defaultText return true } else { log.debug "False" log.debug currentText return false }
Here is the log output:
017-07-25 11:24:44,283 DEBUG [acme.CreateSubtask]: True
2017-07-25 11:24:44,283 DEBUG [acme.CreateSubtask]: h1. Change Plan ---- ||Step||Estimated start time||Duration||Activity||Implementer||Expected Result||Risk Level|| | | | | | | | | ---- h1. Rollback Plan ---- <insert plan text here>
2017-07-25 11:24:44,284 DEBUG [acme.CreateSubtask]: h1. Change Plan ---- ||Step||Estimated start time||Duration||Activity||Implementer||Expected Result||Risk Level|| | | | | | | | | ---- h1. Rollback Plan ---- <insert plan text here>
It's still resolving that the text does not match. Not sure where to go to figure out what throwiung this off.
Any thoughts of what I could try to determine what difference it is finding? Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I ended up solving this by tokenizing the strings. After that the comparison seems to be working as expected:
String defaultText = "h1. Change Plan" + System.getProperty("line.separator") + "----" + System.getProperty("line.separator") +
"||Step||Estimated start time||Duration||Activity||Implementer||Expected Result||Risk Level||" + System.getProperty("line.separator") + "| | | | | | | |" + System.getProperty("line.separator") +
"----" + System.getProperty("line.separator") + "h1. Rollback Plan" + System.getProperty("line.separator") + "----" + System.getProperty("line.separator") + "<insert plan text here>"
defaultText = defaultText.tokenize()
String currentText = cfValues["Change Plan"]
currentText = currentText.tokenize()
currentText != defaultText
Oddly enough, if I print both tokenized strings to the log they look identical, but it works so....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm glad you got it working! :)
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.