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
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, you'll need to add the validator where you need it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nic Brough -Adaptavist- Thanks Nic, help full.
-Tejas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.