Add a way to restart an instance of a workflow, Http Redirect to Form Location Task - This week in Orchard (17/11/2023)

Gábor Domonkos's avatar
Media Library, This week in Orchard, Workflows

Thumbnails for the media library, add a way to restart an instance of a workflow, and a demo about the Http Redirect to Form Location Task! Let's get started!

Orchard Core updates

Thumbnails for the media library

In the media library, there are new icons and thumbnails for well-known file types using Font Awesome icons. Here, you can see the assets provided by the Blog recipe. When you are uploading a PDF or an XLXS file, you can see the new icons instead of the old ones.

Media Library thumbnails

Add a way to restart an instance of a workflow

Sometimes, a workflow instance can fail for some reason, for example, we have a workflow that sends an email and fails. It would be helpful if we could restart the instance. This change adds a button next to the Delete button named Restart. This takes the current workflow state and restarts it.

As you can see here, we have a workflow called test with one faulted instance. If we hit the Restart button near the faulted instance, it creates another instance that can run successfully.

Restart workflow instance

To do that, there is a new RestartWorkflowAsync method in the IWorkflowManager interface, which starts a new workflow using the specified workflow definition.

Each type of activity can implement custom logic when a workflow instance has been restarted because sometimes it needs to load some extra state. This can be achieved by implementing the OnWorkflowRestartingAsync and OnWorkflowRestartedAsync methods. For example, the ContentActivity now stores the content item version ID of the content item that triggered the workflow. It means when you retrigger a workflow, you can use the same version of the content item that you were dealing with before.

The ContentActivity implements the OnWorkflowRestartingAsync method


Http Redirect to Form Location Task

This feature allows you to be able to put a form on a page and then somehow redirect back to that same page where we came from using a workflow. We already have a workflow task that allows us to redirect the user to a specific location, which is great if you know where you want to go back to. Like, if you want to go back to the home page, then you can always redirect the users to the home page. But what if you want to reuse the same workflow for multiple forms (or reuse the same form on multiple pages) and then when the user submits that form, go back to where they submitted the form from? There is no way to do that right now and that's where this demo came from. How can we redirect the user back to the page where they came from?

Now let's create two forms, called the Q&A form and Contact Us, it doesn't matter right now. The thing that matters is they are both using the same URL to submit the form. So, we will have one workflow that will do something, then it will redirect the user back to the source form.

Two forms with the same URL to submit the form to

Here, you can notice a new checkbox called Save Form Location. If we want to redirect the user back to this form, it's required to put a tick into this checkbox to store the location of the form.

It's time to create our workflow! Here, you can see that the starting task of our workflow is an Http Request Event, followed by a simple Notify Task. The last task is a new one, called Http Redirect To Form Location Task.

Workflow to redirect to form location

The last remaining thing to do is to set up our activities. As you can see, the Http Request Event has a new textbox with a label Form Location. It serves as a key that will be added as an entry to the dictionary of re-hydrated values provided to the initiator of the workflow, the Output of the WorkflowContext. Meaning we store the location of the source form under this key in the dictionary.

As you can see, we need to use this key for the Http Redirect To Form Location Task as well. In a nutshell, the Http Request Event stores the source form's URL in a Dictionary with the provided QAContactUsFormLocation key, and the Http Redirect To Form Location Task will read the entry from the dictionary where the key is QAContactUsFormLocation. It allows us to store the location of the source form.

Http Request Event and Http Redirect To Form Location Task activities

And as always, if you would like to know more about this new feature, head to YouTube for a recording!

News from the community

Orchard Dojo Newsletter

Lombiq's Orchard Dojo Newsletter has 485 subscribers! We have started this newsletter to inform the community around Orchard of the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post is published to Orchard Dojo, including This week in Orchard of course.

Do you know of other Orchard enthusiasts who would like to read our weekly articles? Tell them to subscribe here!

If you are interested in more news about Orchard and the details of the topics above, don't forget to check out the recording of this Orchard meeting!

No Comments

Add a Comment