Hi Team,
We have a requirement to validate the field (regression expression) based on the single selection field.
We have 2 fields, "Domain Name" and "Record Name".
If the "Domain Name" is test.com or test.net or test.us, etc,
then "Record Name" field should validate abc.test.com or abc.test.net or abc.test.us, etc
Example : If the user selects the value "test.com" from the field "Domain Name", the user should able to enter abc.test.com in the "Record Name" field.
Hey @Lakshmi CH ,
Good to see you around again. Not sure where or how you would like to apply this, but if it is for create/issue screen - then Behaviours can set this up.
This is just a sample, so you need to match it with your instance. Something like:
import com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def domainNameField = getFieldById("customfield_XXXXX")
def recordNameField = getFieldById("customfield_XXXXX")
def domainName = domainNameField.getValue()
def recordName = recordNameField.getValue()
if (domainName && recordName) {
//the regex pattern
def expectedPattern = ".*\\.${domainName}"
//validation of it
if (!recordName.matches(expectedPattern)) {
recordNameField.setError("Record Name must end with .${domainName}")
} else {
recordNameField.clearError()
}
}
It should show something like this when it is wrong on create/issue screen:
Hope that helps, do feel free to Get Help with us from Adaptavist/ScriptRunner.
Regards,
Sean
Thank you for always being so helpful. We use ScriptRunner a lot. :-)
We want this behaviour on both create and update of the "Domain Name" field. I am getting this error, and its not working. the ticket is creating without validating the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Lakshmi CH ,
The imports are (2 separate lines):
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
=====================
Do give it a go again and see if that works. if it doesn't work, do open a Support Ticket with us to investigate. There could be other issues which may be impacting it.
Regards,
Sean
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oops Sorry @Sean Chua _Adaptavist_ , I have corrected that when you gave me and separated those two in different lines, but its still same error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Team
This is correct code. It validates the custom field value and displays the error.
Note : We should add both fields with the same script (server-side script) to change the validation accordingly.
def domainNameField = getFieldById("customfield_39801") // Domain Name
def recordNameField = getFieldById("customfield_39803") //Record Name
def domainName = domainNameField.getValue()
def recordName = recordNameField.getValue()
if (domainName && recordName) {
// The regex pattern
def expectedPattern = ".*\\.${domainName}"
// Validation
if (!(recordName =~ expectedPattern)) {
recordNameField.setError("Record Name did not end with .${domainName}. Please correct it.")
} else {
// Clear any previous error
recordNameField.clearError()
}
}
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.