How can I access fieldChange in a Workflow validator?

Alexandra Atanasiu
Contributor
September 30, 2024

I have a custom multiple issue picker field shown in a transition screen. I want to validate this field before the transition is executed and prevent a value to be removed from it, in case a certain condition is not met.

I am already checking and doing further processing with the values which are added/removed from this multiple issue picker field in an Automation rule which runs when the field is changed but I cannot also validate and prevent the field change inside an Automation rule (because it happens AFTER the actual field change).

If I try to add my logic to a custom script in the workflow transition validator, I don't know how to access the "previous" value of this field, to be able to check whether the values which were removed are "compliant".

2 answers

1 accepted

0 votes
Answer accepted
Alexandra Atanasiu
Contributor
October 31, 2024

After several attempts, I was able to access it using:

 

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "Custom Field Name")

if (changeItems && changeItems.size() > 0) {
def previousValueOfField= changeItems.last().getToString()
}
Hope this helps anyone else looking for an answer.
0 votes
Sam Hall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2024

Which add-on are you using for your transition validator?

Alexandra Atanasiu
Contributor
October 1, 2024

Hi, Sam! Thanks for checking this.

I am using ScriptRunner for my custom script transition validator.

Suggest an answer

Log in or Sign up to answer