Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner behavior regex

Sysad
Contributor
April 29, 2021

Hi folks

I Am trying to validate a single-line text box to include $ values like $1020.00 and this is the behavior on the custom field. I see no error and still can't have this behavior working

 

def field = getFieldById(getFieldChanged())
def val = field.getValue() as String

if (!val.matches("\$[0-9].[0-9]{2})")) {
field.setError("Amount must be in dollar format.")
} else {
field.clearError()
}

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 26, 2019

The options selected are not strings, they are option objects.  If you want to work with just the option's name (as it appears to your humans), you should use .getValue() to get the name out of the option.

Mahesh Kallepalli
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 26, 2019

Hi @Nic Brough -Adaptavist- 

 

Thanks for your response..!!

def chkBxFld = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10563');

we are getting null pointer exception on null object , Can you guide me on right track with my code as i'm new to scripting.

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 27, 2019

Try

def customFieldName = "Name of your custom field"

def chkBxFld = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField : "Could not find custom field with name $customFieldName"

Like Mahesh Kallepalli likes this
TAGS
AUG Leaders

Atlassian Community Events