Question about jira automation script
Asked by ADM Amar Msaid:

i write a script that is triggered when the issue is created. i want to transitionne the issue to status that is not the first status in the workflow (see inserted image). The first status in the workflow (after the beginning) is ATT_VERIF_CGRH but i want to transitionne the ticket to the ATT_VERIF_PARH status when a certain condition is verified.

i get this message in the log and the ticket id tarnsitionned to ATT_VERIF_CGRH

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

this is my workflow:

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

is it possible to have a second transition from the begining (1) to ATT_VERIF_PARH status (3) and resolve this error ?

Thank you.


Answers:
author: Trudy Claspill
body: Hello [@ADM Amar Msaid](/t5/user/viewprofilepage/user-id/4744840)

Can you please show us the entire automation rule? Often problems are caused by the context in which the step executes. We can't know the context without seeing the rule.

Regarding your diagram, location 1 is not actually a status. It is just a visual indicator of the starting point in the status workflow.

Location 1 can have a transition to one and only one status. When the issue is initially created it will be set to the indicated status (2).

You can use your automation to then transition it to the next status (3), but you can't bypass status (2) based on how your workflow is constructed.

comments: author: ADM Amar Msaid
body: Hi Trudy,

yes, my need is to use automation script to transit directly to status (3) when a condition is meet regarding data collected in the ticket. but it seems that we can't do this in a script triggered when the ticket is created.

i have the same error message when i use action to transit to status (2) even if the transition occure because status (2) is the next status after the begining of the workflow.

it is very easy to reproduce the case. just create a workflow with two statuses and write a script that runs when the ticket is created and that makes a transition to one or the other of the two statuses. you will get an error message and the ticket is still transitioned to the first status.

here the complete rule and error message

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

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

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

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


author: Trudy Claspill
body: When an issue is initially created it is set to the first status in the workflow. The rule is executing after the issue creation is completed and the issues is already set to that first status.

You are getting the error that the issue can't transition to ATT_VERIF_CGRH because the issue is already in that status, and there is no transition to go from that status to that status.

You don't need to try to transition the issue to the first status as part of the rule. That is taken care of during the issue creation process. In your rule you only need to transition it to the next status - ATT_VERIF_PARH


author: ADM Amar Msaid
body: Hi,

My conclusion is that it seems to be impossible to transition a ticket to a status other than the first status of the workflow in a rule that is triggered when a ticket is created.

In my case, I cannot transition to ATT_VERIF_PARH status. That's why there is the second error message.

In a script that runs when a ticket is created, there is no need to use a transition action because the status after creation will be always determined by the workflow (the status linked with the beginning point of the workflow).

do you agree with me?

thank you.


author: Trudy Claspill
body: I don't fully agree with you.

The initial status for a newly created issue is determined by the workflow for that issue. The issue will be set to that status as part of the issue creation process.

A rule that uses an "Issue Created" trigger is triggered ++after++ the creation process is completed for that issue. By the time the rule is triggered and executes the issue already exists and the initial status has been set.

If you can manually transition an issue from that initial status (ATT_VERIF_CGRH) to the new status (ATT_VERIF_PARH) through the UI, then it will be possible to make that same transition happen through an automation rule, if that is what you want to do.

If you want to have a rule that will transition an issue from (ATT_VERIF_CGRH) to (ATT_VERIF_PARH) I would suggest that you start by creating a very simple rule to confirm it is possible to make that change:

```
TRIGGER: Issue Created
CONDITION: Status equals ATT_VERIF_CGRH
CONDITION: <your issue type condition>
ACTION: Transition Issue to ATT_VERIF_PARH

```

If that fails to work share the rule Audit Log with us and we can debug the failure.

There is a lot going on in the original rule you have, making it challenging to debug why the transition may not be occurring. Things to check would include:

1. Review the workflow for that issue type and confirm that a transition exists between the To and From statuses.

2. Check if there are any Conditions or Validators on that transition that might not be getting met when the Automation Rule runs.

3. Check the Actor set for the rule and confirm that Actor has the permissions necessary in that project to transition that issue.


author: ADM Amar Msaid
body: Thank you very much,

i agree with you. i found my mistake. there is a condition that prevented the transition to occurs.

To resolve this, i added permission to project role **atlassian-addons-project-access** to ex?cute the transition from the automation script.


Tags: cloud

jira-work-management-cloud