How can i get the original value of a CUSTOM field using Jira Behaviors? Edited


Can someone provide some code snippet for Jira Behaviors plugin that shows how to retrieve the original value of a custom field?

I need to compare against the original value to see if the field has been changed and take some action if necessary.





3 answers

0 votes

Does this need to be accomplished with behaviours? It sounds like this would be more suited to be done in a listener. For example, you can make a listener that fires on an Issue Created or Issue Updated Event (or all Issue Events). If someone updated the Priority field, check to see what the original value was and what it was changed to. Then, you can perform additional actions based off that information.

def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find{ it.field=='priority' }
if (change) {
def oldValue = change.oldstring
def newValue = change.newstring
log.debug ("Value changed from ${oldValue} to ${newValue}")

// your actions if the field has changed

Log statement:

DEBUG admin [onresolve.scriptrunner.runner.ScriptRunnerImpl] Value changed from Low to High


The requirement is to make the Comment field mandatory if the user changes the custom field.

Aren't Listeners a bit too after-the-fact for my requirements?



Yes, you're correct that listeners wouldn't be very useful in that case. However, your question seemed focus on getting the specific value before and after the field was changed. I don't see why that would be needed if all you want to do is make the comment field mandatory based on a custom field value.

You'd just need a behaviour that would continually check the value of the custom field. It would run on the Create Issue, Update/Edit Issue, Assign Issue, and Workflow Transition screens. If it sees that the custom field has the wrong value, make the comment field mandatory.

def customField = getFieldByName('YourCustomFieldName')
def commentField = getFieldById("comment")

if (customField.getValue() != "Some value") {
else {

If the user changes the custom field to something it's not supposed to be, make the comment field required. Else, don't make the comment field required.

We have a custom field that is a pull-down, so the user can only choose from one of the provided choices.

I need to know if the user selected a different choice of this custom field.  If so, make the Comment field mandatory when the user clicks on "Edit" and changes that custom field.  The Comment field would then be required before the user can click on "Update" to save.

Hi Andrew,

For example:

  • Select List has values A, B, C
  • A is the correct value.
  • If the user clicks "Edit" and changes the custom field and chooses B or C, the comment field will be required.
  • The user will not be able to click "Update" until they provide a comment.
def customField = getFieldByName('YourCustomFieldName')
def commentField = getFieldById("comment")

if (customField.getValue() != "A") {
commentField.setRequired(true) //if the user selects B or C as a choice, make the comment field required
else {
commentField.setRequired(false) //if the user does not select B or C, the comment field will not be required

Does the logic here match what you're trying to accomplish?


My requirement is i don't care what choice is selected.  Every value is correct.

The Comment field is mandatory for the user to explain why the custom field value was changed.




If I may be so bold,

Why don't you simply create a transition for this?

If this field is required at creation, then put it on the Create and View screens only, and leave it off the Edit screen.

The tranisition could be from all to all, called something like "Update MyField," and you can put this field and the comment field on the screen for this transtion.

Then simply require Comment on the transition using a validator.

Would this cover your requirement?

Thank you for the suggestion, April.

I think this is a bit much for my requirements.

The field is required during Create as well as Edit.



Hi @Joshua Yamdogo [Adaptavist], how can I revert back the original value if the custom field has set to blank/null in a group picker field?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Jira

How you can achieve compact and easy-to-maintain workflows in your JIRA( Server)

This approach requires you to have the JIRA administrative rights. The main aim of this article is to help you achieve an organized, easy-to-maintain workflows in your JIRA instance thereby, reducin...

243 views 0 0
Read article

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