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: 

scriptrunner validation to check custom field starts with a partial word

Sapir Monza
April 1, 2019

Hi, I am trying to create a workflow transition validation

I need to check that custom field "Escalated case number" starts with a partial word, for example, "SER-" or "AT-".

I tried it with:

cfValues['Escalated case number'] ~ "SER-"

But it doesn't work. Someone know how can I make it?

Thanks

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Antoine Berry
Community Champion
April 1, 2019

Hi,

You could use 

cfValues['Escalated case number'] ~ "SER-*"

Or write a custom groovy script since you are running script runner.

Sapir Monza
April 1, 2019

Thanks for your answer.

But when I tried this, I get the error:error.png

Antoine Berry
Community Champion
April 1, 2019

Oh I see, you need to use a groovy script here. You can use this one,  just change the custom field id : 

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

//Jira User picker ID
int caseNumberId = 10100
def cfCaseNumber = customFieldManager.getCustomFieldObject(caseNumberId)
def cfCaseNumberValue = issue.getCustomFieldValue(cfCaseNumber)

if (!cfCaseNumberValue.startsWith("SER-"){
invalidInputException = new InvalidInputException("The Escalated case number is not correct. It should start with SER-")
throw invalidInputException
}

Antoine

Like desarrollo likes this
Sapir Monza
April 1, 2019

I'm still getting some errors:

error2.pngerror1.png

Antoine Berry
Community Champion
April 1, 2019

Do not worry about these warnings, since it is groovy it will evaluate on execution and work fine.

Sapir Monza
April 1, 2019

Just to clarify I'm adding this script as a validator on workflow transition

Antoine Berry
Community Champion
April 1, 2019

That is exactly what this script is aiming at. :)

Sapir Monza
April 1, 2019

Thanks it works fine :)

Antoine Berry
Community Champion
April 1, 2019

Glad to help ! You can mark the answer as accepted to lead other users with similar issues on this topic.

TAGS
AUG Leaders

Atlassian Community Events