Jira validator with invalid_fields doesn't work

charly_gaulay November 20, 2015

Hi,
I've written a script in jython to validate a transition.
But in error case, when i use description and invalid fields variables, the transition fails but there is no error on concerned fields.
Have you any idea ?
Thanks in advance,
Regards

 

Thanks for your answer.

I would like to display a clean error message on a failed transition with json script validator.


i use a jython script to validate a transition.

description = "example fields must filled correctly"
	invalid_fields[cfm.getCustomFieldObjectByName("example")] = u"example fields must filled correctly"


For example, i check if some fields are filled in correctly otherwise i would like to display an error message.
I've seen with JSS plugin (JIRA Scripting Suite) it's possible with jython context variable to display an error message on concerned fields.

The two variables are "description" and "invalid_fields".


Do you understand my problem ?

Thanks 

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
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.
November 20, 2015

If the fields are not valid for the project/issuetype, then I suspect it has nothing to fail on.  It can't say "this field is wrong" because the field simply isn't there.

But I could be misunderstanding the question and what you're doing.  Maybe post the relevant part of the jython (and a note on how you're running it in JIRA might help for context)

charly_gaulay November 23, 2015

Hi, 

I want to diplay a JIRA error message if my jython validator script fails.

It is possible and how to do this ? 

Thanks in advance,

Regards

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.
November 23, 2015

I don't know if it's possible, you have not explained how you are running the jython in JIRA.

cgaulay November 23, 2015

Hi, For a specific workflow, I've added a validator (wrote in jython) for a transition between two states. If this validation fails, i want to display a JIRA message for explain why. My script works fine but the error message displayed when there is an error is not very user friendly.

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.
November 23, 2015

For the third time, you need to explain how you are running the jython.

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.
November 23, 2015

Before you ask, JIRA does NOT allow you to write functions like that, you need to explain how you are running it.

cgaulay November 23, 2015

Hi, I've installed Jira Scripting Suite plugin which allow to put custom conditions, validators, etc.. in workflow with Jython Scripts. In Jython Scripts, I can use python methods and java methods. Currently, for stopping Jython script execution and display errors I use "raise" python method but the message is not very user friendly because it's a Python exception. That's why I would like to use jira api to display error messages when the validator fails.

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.
November 24, 2015

Right, I was going to post, but you found it for yourself. There's no way to do this with some add-ons that allow scripting, and others have totally different methods, so I couldn't really help you. Glad you got there!

0 votes
charly_gaulay November 25, 2015

I've a last question.
conditions scripts are called after all modification or just after the previous transition ?
If i modify a field which condition a transition, available transition will be updated or not ?

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.
November 25, 2015

No! * A condition checks to see if the user can *start* the transition. Effectively, they run whenever you look at an issue in any way that you might be able to move it through the workflow so that JIRA can work out whether to show you the transition, or let you start it. * A validator runs when the user *tries to commit* the transition and checks the data is valid. * A post-function runs when the user *commits* a valid transition

0 votes
cgaulay November 24, 2015

Hi,
I've found a workarroud to display errors correctly. I use a screen on my transition to display some fields and when i add errors on a field with :

invalid_fields[cfm.getCustomFieldObjectByName("example")] = u"example fields must filled correctly"

Error is correclty displayed on transition.

 

However, it is possible to associate a screen with transition only on specific issue like a critical issue for example ? 

Thanks

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.
November 24, 2015

Yes, look at the workflow transitions. Every transition has a "screen" which can be set independently of everything else. One trick to consider in your case here might be to set up a Screen for your critical issues and then have the workflow have *2* slightly different transitions. Let's say you're going from "open" to "in progress" - create two transitions from open to in-progress - on one of them, use your screen - on the other, do not put the screen on it (or use a different one) - on the first transition, place a condition for "Priority = Critical" - on the second, place a condition for "Priority != Critical" The users will only ever see one transition available, and they'll only get your screen on "critical" ones.

charly_gaulay November 24, 2015

It's working ! Thanks a lot for your help !

TAGS
AUG Leaders

Atlassian Community Events