The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

How to validate some set of string in a text field?

Teja
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.
November 14, 2019

Hello,

I am trying to add a validation which catches 'Caused By Explanation' string inside a multi text field. And throws an exception to show users saying 'Caused By Explanation' is not a valid value.

How to achieve this? 

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Leo
Community Champion
November 15, 2019

Hi @Teja,

Below snippet may help you

import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException

def cField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Caused By Explanation")
def value = issue.getCustomFieldValue(cField) as String

if (value == "Something"){
return true
}
else{
throw invalidInputException = new InvalidInputException("Custom Error")
}

 BR,

Leo

Teja
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.
November 21, 2019

@Leo Thanks, It worked.

Regards

Tejas Naik