const changedField = getChangeField();
const regex = /\\d{7,}\\s*\\d{7,}/
if (changedField.getType() == "com.atlassian.jira.plugin.system.customfieldtypes:textfield" &&
changedField.getName() == "My Customfield" &&
!regex.test(changedField.getValue().toString())) {
getFieldById("customfield_10050").setDescription("Correct");
} else {
getFieldById("customfield_10050").setDescription("Wrong");
}
I actually solved it with this code. Instead of textfield I changed it to textarea and it worked. I also changed the regex to the below format.
const changedField = getChangeField();
const regex = /^(?:(?:\d{7,}\s+){0,2}\d{7,})$/; // Simplified regex
const logs = !regex.test(changedField.getValue().toString())
logger.info(logs.toString())
if (changedField.getType() == "com.atlassian.jira.plugin.system.customfieldtypes:textarea" &&
changedField.getName() == "My Customfield" &&
!regex.test(changedField.getValue().toString())) {
getFieldById("customfield_10050").setDescription("Correct");
} else {
getFieldById("customfield_10050").setDescription("Wrong");
}
Hey Rodrigo,
I think it is something to do with your statement for regex, maybe the \\ in
const regex = /\\d{7,}\\s*\\d{7,}/
or something with the script call to
"com.atlassian.jira.plugin.system.customfieldtypes:textfield"
Nevertheless, I do have another use-case which is similar to yours but our scripts are different, you can check out my sample here : ScriptRunner Jira Cloud - Behaviours (Regex description change)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rodrigo,
I can confirm that Behaviours in Jira Cloud use Javascript so you can use Javascript Regex in the script.
However, if you are getting the value of a paragraph field, please note this field is returned in Atlassian Document format, so you will need to handle this Syntax in your script.
If you need further assistance, then I would advise you to raise a support ticket here.
I hope this information helps.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kristian Walker _Adaptavist_ ,
I actually solved it with this code. Instead of textfield I changed it to textarea and it worked. I also changed the regex to the below format.
const changedField = getChangeField();
const regex = /^(?:(?:\d{7,}\s+){0,2}\d{7,})$/; // Simplified regex
const logs = !regex.test(changedField.getValue().toString())
logger.info(logs.toString())
if (changedField.getType() == "com.atlassian.jira.plugin.system.customfieldtypes:textarea" &&
changedField.getName() == "My Customfield" &&
!regex.test(changedField.getValue().toString())) {
getFieldById("customfield_10050").setDescription("Correct");
} else {
getFieldById("customfield_10050").setDescription("Wrong");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rodrigo,
I am glad you managed to solve your issue.
Regards,
Kristian
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.