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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,301
Community Members
 
Community Events
185
Community Groups

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

Edited

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

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.
Oct 04, 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)

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")

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.
Oct 03, 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.

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.
Oct 06, 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()

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.

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.
Oct 12, 2022 • edited

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.

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?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.1
TAGS
AUG Leaders

Atlassian Community Events