Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Validate a value of a custom field based on state using script runner

Nannette Mori October 3, 2022

Jira version 8.20.1

Script runner version6.56.0

 

I want to check on a value of a customfield and throw a message if the value is not valid and not allow transition to the next state.  i know I can put a validator on a transition but I do not want the user to be able to put a invalid value in that custom field in between state changes.  Is there a way to validate the value when transitioning to a certain state and not allow an invalid value between state changes using script runner

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Dirk Ronsmans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 4, 2022

Would a behaviour help here?
On the edit of the field you do your checks and include the current state of the issue as well...

By using the setError() function you can also throw a custom error message on that specific field and it won't allow them to save the issue.

This is something we often use to validate input regardless of the state to be sure the value has a certain format (often with a regular expression attached)

Nannette Mori October 6, 2022

The problem we are having is we can't get the current status of the issue.  We used what was in script runner documentation and script runner isn't recognizing the functions

This is from Script runner documentation

 

import com.atlassian.jira.component.ComponentAccessor

def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)

def wfd = workflow.getDescriptor()

def actionName = wfd.getAction(transientVars["actionId"] as int).getName() log.debug("Current action name: $actionName")

Nannette Mori October 6, 2022

we were trying to use these functions in script runner behaviors

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 3, 2022

No, Jira does not have any hooks on the "edit" action that you could plumb a script into.

The closest you can get would be a listener that picks up edits, checks what the users have put into it and changes it to something valid if they've made a mistake.

You'll still need validotrs on the transitions as well.

Nannette Mori October 6, 2022

The problem is we can't access the current state of the issue.  

How do we access the current state of the issue using Script runner

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 6, 2022

In a scripted listener, you would extract the issue from the event, and then get the status from the issue.

def issue = event.issue

def status = issue.getStatus().getName()

Nannette Mori October 7, 2022

Thank You for your assistance.

What is the syntax for the function below in a listener?

 

By using the setError() function you can also throw a custom error message on that specific field and it won't allow them to save the issue.

Nannette Mori October 12, 2022

so using a listener won't work because we don't want to allow the user to save the issue.

Can you do this using behaviors?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 12, 2022

A listener can't stop an edit.  It is running after the edit is complete.

You could do something with Behaviours on the edit screen, yes.

Nannette Mori October 18, 2022

The problem I am trying to solve is users are changing the Value of the Delivery Field to 6.x in between state transitions. Can you throw an invalid exception error in Behaviors?  How do you access the current state in Behaviors?

DEPLOYMENT TYPE
SERVER
VERSION
8.20.1
TAGS
AUG Leaders

Atlassian Community Events