Changes not saved when transition validation is false

Marcelo Mella January 1, 2020

I have create a validation script in one transition.
I added a customfield update in the validation, so is something like this

if validation == true

{ MutableIssue mi = (MutableIssue) issue; mi.setCustomFieldValue(CampoAPPT, "En Progreso"); ComponentAccessor.getIssueManager().updateIssue(currentUser, mi, EventDispatchOption.ISSUE_UPDATED, false); return true }

else

{ MutableIssue mi = (MutableIssue) issue; mi.setCustomFieldValue(CampoAPPT, "No Agendado"); ComponentAccessor.getIssueManager().updateIssue(currentUser, mi, EventDispatchOption.ISSUE_UPDATED, false); return false }

If i execute this in the console, i get the customfield updated in both cases. But if i do the transition, false validation doesn't update the field

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 1, 2020

Validators should not update fields.  A validator is for checking input, and the only thing they do is return a pass or a fail (with an error message, optionally)

Do not try to do this.  Move the custom field update into a post function, after you know the person has entered something that is valid.

Marcelo Mella January 1, 2020

The reason why i'm using a Validator is that my script calls a REST API on another platform.

If the call goes OK, i do the transition.

But if the call fails, i would like to update a customfield and add a comment.

 

As far as i can see, when validation fails, the update doesn't run.

Is there a way to force the issue (mutable issue) to be saved?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 3, 2020

The update can't run, you have not got to the point where you can write anything to the issue in a validator.

You will need to validate first, returning a pass or fail, and then do the update in a post function.

Suggest an answer

Log in or Sign up to answer