Going "back" to a previous activity

Let’s say I want to go “back” to a previous activity. Is there a way to do that? Or is the only way to do that something like this:

firstActivity()

const [goBack] = secondActivity()

if (goBack) {
firstActivity()
}

You can use control-flow logic such as data-based decisions or looping constructs inside your workflow code.

Maybe something like this could be useful, in your workflow code:

    // workflow method code
    while(runActivities());
     // ....

and runActivities (in your workflow class) could be

    private boolean runActivities() {
        activities.first();
        return activities.second();
    }

Just note that a single workflow execution has a 50K event history limit and you probably dont’ want to loop here too many times as each activity invocation (scheduled, started, completed events) are recorded in history.

Thanks for the reply @tihomir . Could you clarify what you mean by “workflow class”? Is that just the activity code, e.g. activity.js in the hello work examples? Or do you mean a helper function in the workflow code? If it’s in the activity.js code, that means that I won’t benefit from first() and second() being separate activities.

Is there a way, instead, for Temporal to reconstruct the vm state but without the step we are trying to undo? Instead of using a loop.

Thanks!

Helper function in the workflow code. Sorry I wrongly assumed you are using Java SDK :slight_smile: (you can tag the sdk used when you start a post btw)

Is there a way, instead, for Temporal to reconstruct the vm state but without the step we are trying to undo? Instead of using a loop.

Can you share your use case for wanting to do that? Typically you would handle an activity failure and run compensation, for example execute another activity or a set of that compensate for it.

Ah thanks @tihomir , I added the typescript-sdk tag!

Can you share your use case for wanting to do that?

In our case, each activity involves downstream user interaction. Users can choose to go “back” to a previous activity if they want to (essentially rewinding to a previous step in the workflow). Is the while() construct the best way to do that? Are there any lower-level APIs we could use instead that change the underlying temporal state?

Thanks again!