Update status depending on field value via JMWE
Asked by Anette Noll:

Hi all,

would be great if someone could put me on the right track with regard to the following scenario:

1. New issue is created  
   Create screen contains custom field with value 1, 2 or 3  
   Conditions:  
   if custom field contains 1, than status is set to status A after clicking *create*   
   if custom field contains 2, than status is set to status B after cklicking *create*   
   if custom field contains 3, than status is set to status C after cklicking crea*te*   

2. Every time the issue is updated it looks which value (1, 2 or 3) shows up and sets the status accordingly.

Is there is any solution with the help of JMWE? I am very curious to learn how this works.  

Thank you.  


Answers:
author: David Fischer
body: Hi [@Anette Noll](/t5/user/viewprofilepage/user-id/4198653)

Jira doesn't allow the status of an issue to be changed directly. Instead, it uses *transitions* defined in the *workflow* to move issues between statuses.

Therefore, to achieve what you're trying to do, you need to use a Transition Issue(s) post function to automatically trigger the appropriate transition on the issue.

So the first thing to do is ensure you have "global transitions" in your workflow that go from *any status* to the A, B, and C statuses.

Then, the easiest is to create a Shared Action that contains 3 Transition Issues post function, each triggering the transition to status A, B, and C, respectively, and each with the required Conditional execution to run it only if the custom field has the appropriate value.

Then, you can:

* add a Shared Action post-function to the Create transition of your workflow to run the shared action you just created
* create an Event-based action that reacts to the Field Changed event, for your custom field, and in the post functions of that event-based action, add the same Shared Action post-function to run the shared action you just created

The advantage of using a Shared Action is that if you need to modify the configuration (say, add a 4th custom field value and destination status), you will make changes in a single place only (the share action).

comments: author: Anette Noll
body: Hi [@David Fischer](/t5/user/viewprofilepage/user-id/538255)

Thank you so much for response and your explanation.

But it seems that I make a mistake while following your points.  

In the moment I create a new issue the following happens:

* Custom field contains value 2, status B is expected after creation
* What happens is that the newly created issue changes successively through all statuses (A, B and C) automatically
* Concerning the event based action I wonder how I integrate it in the workflow

![Jira_S.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/329178i87E4DE0A05D5AC35/image-size/large?v=v2&px=999 "Jira_S.PNG")


author: David Fischer
body: Hi [@Anette Noll](/t5/user/viewprofilepage/user-id/4198653)

from what I can see (your screenshot is not very legible), you didn't provide a "conditional execution" script but instead a comment text. You need to add what you put as comment text in the Conditional Execution option.


author: Anette Noll
body: Hi [@David Fischer](/t5/user/viewprofilepage/user-id/538255) ,

thanks again for response.

It works almost completely, but I am still facing two problems:

* All postfunctions in the shared action show errors.  
  I guess that this is because of this:  
  if field value changes and issue has been refreshed, status plays kind of ping pong until finally the correct status is displayed. Any solution to this?  

  ![Jira Errors.png](https://community.atlassian.com/t5/image/serverpage/image-id/329479iD8F823254D26AB3A/image-size/large?v=v2&px=999 "Jira Errors.png")
* only one post function does not produce the expected Jira status.  
  Expected status is Approved - issue refresh and the following happens:  
  approved - in progress - approved - it stops and stays with "in progress"  

  I cannot find any significant difference between postfunction that produces correct status (green frame) and postfunction that produces incorrect status (red frame). What am I overlooking?  

  ![Jira Errors Gegen?berstellung.png](https://community.atlassian.com/t5/image/serverpage/image-id/329481iBDD018BDDE32DF4D/image-size/large?v=v2&px=999 "Jira Errors Gegen?berstellung.png")  


author: David Fischer
body: Hi [@Anette Noll](/t5/user/viewprofilepage/user-id/4198653)

Regarding the errors, you'd need to expand one of them to see the actual error details and share that here.

Regarding the status changing on the screen, it's a limitation of Jira Cloud, it updates the status "lazily".

As for the transition that fails, you need to check if it has a transition screen and a validator that prevents the transition from happening. You can try to manually trigger the Approve transition and you'll see if there's any requirement during that transition.


Tags: cloud

jira-cloud