How to throw an validation message on transition screen using Jira event listener plugin?

Teja
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.
July 1, 2019

Hi Team,

I would like know how to throw an validation message on the workflow transition screen using the EventListener plugin, since I am new to SDK.

I have written a java condition to check my 'Target Version' field (version picker) is equals to my first unreleased version, if not tell user that validation checks.

My java file will be like this

@EventListener
public void onIssueEvent(IssueEvent issueEvent) {

Issue issue = issueEvent.getIssue();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField targetversion = customFieldManager.getCustomFieldObject("customfield_11400");
Object targetversionvalue= issue.getCustomFieldValue(targetversion);
Object targetversionvalue1= targetversionvalue.toString().replace("[", "").replace("]", "");
VersionManager versionmanager=ComponentAccessor.getVersionManager();
Collection<Version> version=versionmanager.getVersionsUnreleased(10207L, false);

Object versionvalue =version.iterator().next().toString();
if (targetversionvalue1.equals(versionvalue)) {
log.warn("Inside if loop....." );
throw new InvalidInputException("Target Version should be earliestUnreleased version");
}

}

I cannot able to do using throw class.

Since 'Target Version' validation check need throughout the workflow and other projects, so my manager need this check centralized so I developed EventListener Plugin.  

Regadrs

Tejas

1 answer

1 vote
Nic Brough -Adaptavist-
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.
July 1, 2019

You don't.

It's nonsense to do validation in an event because they are a response to something being done, not part of the activity.  It's too late in the process.  The user has already changed the values and the change has been committed into the data.  The firing of the event is the very last thing that happens in the change process.

You need to write this as a validator or Behaviour.

Teja
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.
July 1, 2019

Hi @Nic Brough -Adaptavist- ah...ha!

That's I wanted to hear from you guys.

So if I create a workflow validator, I need to go & add validator each and every workflow transition using 'Target Version'. Ok that is fine I can add for the first time.

If I make any changes to java file, do I need to remove and add for the second time each and every workflow transition?

- Tejas

Nic Brough -Adaptavist-
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.
July 2, 2019

No, you'll need to add the validator where you need it.

Like Teja likes this
Teja
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.
July 3, 2019

@Nic Brough -Adaptavist- Thanks Nic, help full.

-Tejas

Suggest an answer

Log in or Sign up to answer