Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the current and destination status using script runner v 6.56.0

Nannette Mori
Contributor
January 20, 2023

I need to check the current status and destination status

if current status = (status) and Destination status = (status)

{

   then I need to allow the transition even though the the field contains x

{

The documentation stated myIssue.statusObject.name will return the current status if your script function is before the built-in post functions to update the issue, it will return the previous status, if the script function is put after the built-in functions it will return the destination status.  I need to get the current status and the destination status in my script - but the documentation states to get current and destination status has to be placed in different locations in the post function area..... 

Is there another way to get the current and destination status?

 

 

1 answer

0 votes
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.
January 21, 2023

This is actually quite hard to do in a script. 

Current status is easy - there isn't one on the "create" transition, and issue.status will give it to you in all the others.

For target though, you have to work out what the current workflow is, and then which transition it is.  You'll then need to look at the internals of the transition, look it up in the workflow, and then extract the end status.

I've explained it that way around because you mention  "if the script function is put after the built-in functions" - you must not do that.  A post-function is too late to perform validation.  Your code is only suitable for a condition (stops Jira showing the transition to people) or validator (checks data is valid before running the transition)

So the next question is why you're trying to do it this way.  Conditions and validators are added to transitions individually, so you can do "if field has X, allow or block it" without looking at end status.  Scriptrunner even has a built-in script that can flexibly do that (no coding needed), and other automation apps support similar conditions and validators

Nannette Mori
Contributor
January 25, 2023

We have a behavior that checks a Fix Version Checker customField for a valid fix version in certain states.  If the field contains a X value we throw an error. We have a transition validator that will allow a .x value when transitioning from DRAFT -> In DRRB Review.  Once the issue Record is in "In DRRB Review" we no longer allow .x value so if that issue record was modified the user would have to update the .x value to a valid version.  In DRRB Review Status transitions to "Not Approved or "Approved.  If the Issue needs to be transitioned to "Not Approved" I cannot transition to "Not Approved" because the Issue is technically still in "In DRRB Review" so the error is thrown to update to a valid version and does not allow the transition.  The user would have to update to a valid version before transitioning to "Not Approved".  We do not want the user to have to update from an .x version to a valid version if transitioning to Not Approved because we clear that field if the DR transitions to "Not Approved".  How do we allow the transition fro "In DRRB Review to "Not Approved when the Issue is in "In DRRB Review" so the behavior throws the exception, and we cannot transition to "Not Approved"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.22.6
TAGS
AUG Leaders

Atlassian Community Events