Challenges Using Workflow in Pages
A lot of the time one will associate workflow only with page items in Sitecore. Especially when you’re using Sitecore Pages in XM Cloud. It’s completely understandable, especially as you’re working largely from a page-only perspective. The issue however is that in Pages, once a component has been added to a page, any subsequent change to the page, outside of changes to page specific fields, aren’t happening to the page. Those changes you’re making, they’re likely happening to the datasources supporting the page. That’s where the dangers lie, especially when those datasources do not have a workflow on them.
Workflows on Datasource Items Are Not Just Beneficial, They’re Crucial
While you might immediately think having workflows on page items may be all that’s necessary, having them on datasource items is more than just a nice-to-have, they’re vital. Without a workflow on a datasource, if a person was to publish the page that is in workflow, if the previous version of said page has that datasource connected to it, it will be published as well. This means any changes you may have thought were within a workflow are now live to the world. That’s because of the way that publishing in XM Cloud happens. Unlike the old way where a page could be published separate from its datasource, in XM Cloud, the layout of the page is rendered during publishing, meaning the data within the datasource is grabbed at that time.
In Pages, you can get immediate feedback that a datasource has a workflow when upon editing text within the component, you’ll get a prompt that a new version of said datasource has been created and entered workflow. If you’re not seeing that message, there are only a few reasons for it. Either you’re on your local environment, you’re an admin, or the component doesn’t have a workflow attached to the datasource’s templates.
Having a datasource in workflow is just part of the solution though. There is presently no way within Pages to alter a components datasource version or move it through workflow. You’d have to go back to Content Editor to manage it.
Let’s now link Page workflows and Component workflows so that they are in sync. We can do that with what’s called, Datasource Workflow Actions.
What Are Datasource Workflow Actions?
Datasource Workflow Actions are a useful Powershell script that we can add to our item workflows to link the workflow of a Page and that of one or more components. In our example below we’re going to link the Page workflow “Demo Workflow” to the Hero Banner’s workflow “Demo Datasource Workflow”.
Now in both of our cases, the steps in both workflows are identical. This is in many cases the best way to handle workflows because then we can more accurately link steps. That’s not to say you can’t complicate workflows if the client desires, but to have an identical set of steps means that as a page progresses through workflow, the components do at the same rate.
Linking Page And Datasource Workflows
Let’s link our Demo Workflow
to our Demo Datasource Workflow
such that when we’re on a page and we need to move through the workflow states of the page, it too triggers identical steps on the datasource.
Navigating to the Demo Workflow
item, we’re going to create a Datasource Workflow Action
under Submit
. So right-click on the Submit item under Draft, and Insert > Datasource Workflow Action.
We’re then going to do the same under Awaiting Approval. Once done you should have two items like so.
In the Command Item
field we’re going to connect it to the Submit
item inside our Demo Datasource Workflow, as shown below.
Similarly, under Awaiting Approval, we’re going to link the Command Item
field to the Approve
item in the Demo Datasource Workflow.
So what does this all do? Well, now, if we’re in Pages and our Page is in “Draft”, when we submit for approval, it will in turn submit any datasources on the page that are also in Draft into the Waiting for Approval state as well.
So now, when in Pages, if I use the workflow “Action” and Submit for Approval, then both the page item and the banner’s datasource will enter the same workflow state.
Never Forget About Workflows
Workflows, while developers and administrators might feel like they impede construction of a site, they’re something that absolutely needs to be in place when it comes to authoring a site. Things like version control and auditing of approval and publishing steps is all too commonplace these days to forget them and leave them to the last step.