How To Validate Against Value of a Field Changed on the Transition Screen

I'm using Script Runner on Jira 6.17 to write a Validator script.

Validation works fine, except when the field I validate against has been changed on the transition screen.Then I still get the old value of the field.

I use issueManager.getIssueObject(issue.id).getCustomFieldValue("Custom field name") to get the field i want to validate, but this field has not been updated with the users change on the transition screen. Im guessing that it is because the value is updated during the post function phase of the transition.

How do I get the value of the field that is on the transition screen?

2 answers

1 accepted

2 votes

I'm not sure Benji's answer is right.

Your problem is that you're reloading the issue from the db rather than just using the issue object provided to you in the binding.

issue.getCustomFieldValue(CustomField)

should work fine. No IssueManager.

You are right, I tried your solution and now it works well.

Thanks for the help Jamie!

Hi Stefan,

Unfortunately this is not possible with validators. A validator is intended to check the values before a transition is executed (https://confluence.atlassian.com/display/JIRA/Configuring+Workflow).

You have 2 options:

1) Write a post function that does the validation at the end of the transition

2) Add a validator at the begining of the next transition that validates the values entered in the previous transition

Thanks for your quick reply Benji.

As Jamie suggested it works now when I just access the issue object.

Your statements are contradictory. If what you have mentioned "A validator is intended to check the values before a transition is executed ", is true, then how is the validator given an option to perform an Field Modified function to check whether a field is modified in the transition screen or not??

In my validator script i have access to both what is the current state with values that might have been modified in the transition screen (that is the issue object named issue available in the script), and how the issue actually looks like in the database, eg with no modifications made. So the "issue" object contains the information the issue contains in the transition that have not yet been saved. And the issue object i get from "issueManager.getIssueObject(issue.id)" is the database version of the issue. That is how it really is. In the validator i just compare the values contained in the customfields, and if they differ a modification has been made on the transition screen. Hope this answer your question.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Posted 7 hours ago in Jira

We want to know what Jira Service Desk apps you're using!

Hi Community! My name is Amir and I’m on the Jira Service Desk product marketing team at Atlassian. Our team would love to understand how you’re leveraging our ecosystem for Jira Service Desk. Wha...

26 views 0 5
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you