# How to jump to previous step then run to end?

**URL:** <https://community.temporal.io/t/how-to-jump-to-previous-step-then-run-to-end/3468>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [November 24, 2021, 2:11pm UTC](https://community.temporal.io/t/how-to-jump-to-previous-step-then-run-to-end/3468 "2021-11-24T14:11:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![willis](https://avatars.discourse-cdn.com/v4/letter/w/74df32/32.png) [@willis](https://community.temporal.io/u/willis)\
**Post date:** [November 24, 2021, 2:11pm UTC](https://community.temporal.io/t/how-to-jump-to-previous-step-then-run-to-end/3468/1 "2021-11-24T14:11:06Z")

</div>

Hi，

In our company, we have a business workflow with 20+ steps(Activities). For any step, user is able to go back to previous step. Just wondering what the best practice for this cases? Taking below as example.

1. Step 1 - Get level one’s approval
2. Step 2 - Get level two’s approval
3. Step 3 - Get level three’s approval
4. Step 4 - Get level four’s approval

In Step 4, User can ask level 2 to check again and then go to Step 3, Step 4.

Do we have a “Go to specific step” feature ?

Thanks,  
Willis

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 24, 2021, 3:08pm UTC](https://community.temporal.io/t/how-to-jump-to-previous-step-then-run-to-end/3468/2 "2021-11-24T15:08:11Z")

</div>

Can you explain what “user can ask” means in your application?  
Temporal supports signals, async events that are delivered to a workflow, and usually external user input is modeled as a signal.

There is no out-of-box “goto” feature, but believe you can accomplish your goal with combination of waiting for signals (user inputs), and using programming language constructs to define your activity invocation logic based on those inputs.

---

<div class="post-metadata">

**Author:** ![willis](https://avatars.discourse-cdn.com/v4/letter/w/74df32/32.png) [@willis](https://community.temporal.io/u/willis)\
**Post date:** [November 25, 2021, 2:31am UTC](https://community.temporal.io/t/how-to-jump-to-previous-step-then-run-to-end/3468/3 "2021-11-25T02:31:50Z")

</div>

Thanks for your response.

“User can ask” means user is able to select one step from UI and ask workflow to go to that step.

Yes, I agree with you. It’s a kind of signal. We write some code to achieve such feature like below.

1. Once we got the signal from user to go to previous step, we close current workflow execution
2. Then we start a new execution with same workflow id with the context.

Am I on the right way? ut there are some state need to be stored and recovered. Like if user want to go to Step 3, we must restore all state for Step 1 & 2, skip them and start from step 3.

Thanks for your time again

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 26, 2021, 3:33pm UTC](https://community.temporal.io/t/how-to-jump-to-previous-step-then-run-to-end/3468/4 "2021-11-26T15:33:03Z")

</div>

> [@willis](#):
>
> - Once we got the signal from user to go to previous step, we close current workflow execution
> - Then we start a new execution with same workflow id with the context.

Instead of closing the current run and starting a new one, you could instead continue your current workflow exec as a new, and pick what parts of current workflow data to pass to the next execution.

You can use `Workflow.continueAsNew` when signal is received, or you can pre-define  
your continue-as-new stubs (maybe for each of the steps), for example:

```auto
private final Step2Workflow continueAsNewStep2 =
        Workflow.newContinueAsNewStub(Step2Workflow.class);
...
// when signal received for step 2
// stop execution of the current workflow and start a new execution
continueAsNewStep2.doStep(input, input2, ...);

```

There is no “go-to” specific feature that I am aware of, but this should be close enough hopefully.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [November 27, 2021, 8:06pm UTC](https://community.temporal.io/t/how-to-jump-to-previous-step-then-run-to-end/3468/5 "2021-11-27T20:06:10Z")

</div>

It can be as simple as a loop that chooses which step to execute based on the current state:

```auto
loop {
   switch (state) {
      step1: ...
      step2: ...
      step3: ...
      step4: ...
}

```

Then update the state based on user input. Obviously, you can create a more complex design that doesn’t hardcode steps but uses some DSL to specify them.

---

<div class="post-metadata">

**Author:** ![willis](https://avatars.discourse-cdn.com/v4/letter/w/74df32/32.png) [@willis](https://community.temporal.io/u/willis)\
**Post date:** [November 29, 2021, 10:54am UTC](https://community.temporal.io/t/how-to-jump-to-previous-step-then-run-to-end/3468/6 "2021-11-29T10:54:33Z")

</div>

Thank you. Both, Team is trying both approaches to find one appropriate solution for us. We will back to you later
