Send Sitecore workflows notifications to users based on Sitecore roles
In many Sitecore solutions, there are different areas, where different editors and publishers maintains content in their respective areas. Sometimes these areas overlap.
In this blog post I will give an example of how to send workflow notifications to the different publishers and editors without being restricted to where in the structure the item is created/edited.
In this example, I have a Publisher Role and an Editor Role, where access rights to workflow commands and other Sitecore roles has been added.
The owner roles (owner publisher and owner editor) will inherit from these roles. the owner roles are primarily used to control which users should get notifications in this example, I also use, the owner set on the item to control access rights programmatically but I won't cover this in this blog post.
Since the publishers and editors will be given different roles we can on item creation set this droplink field programmatically based on their role:
/?sc_mode=edit&sc_itemid=" + contentItem.ID
In this blog post I will give an example of how to send workflow notifications to the different publishers and editors without being restricted to where in the structure the item is created/edited.
Creating a connection to roles and the Sitecore item
I created a droplink field on the Sitecore items which use workflows so we can connect this item to the corresponding roles.
The droplink is populated based on a data folder with items that has the Roles specified.
In this example, I have a Publisher Role and an Editor Role, where access rights to workflow commands and other Sitecore roles has been added.
The owner roles (owner publisher and owner editor) will inherit from these roles. the owner roles are primarily used to control which users should get notifications in this example, I also use, the owner set on the item to control access rights programmatically but I won't cover this in this blog post.
Since the publishers and editors will be given different roles we can on item creation set this droplink field programmatically based on their role:
Creating worflow notification on Submit
On the submit command I created an action NotifyOnSubmit, here I send an email to all the publishers who has the corresponding role as the owner of the item. I could have used the current role of the logged in user, but this was not always the correct action when I created this logic. for another solution that would probably be a better approach
Creating worflow notification on approve
On the awaiting approval command I created an action NotifyOnApprove action. Here we send an email to all the publishers and super administrators in the solutionCreating workflow notification on Reject
On the awaiting approval command I created an action NotifyReject action, Here we collect the last workflow history to get the correct email we should send the reject notification toSetting the owner field as required
For all templates which have the workflow added, it is required to have the owner set on the Sitecore item for workflow notifications to be sent to the correct users. this is partially covered by setting the owner on item creation, however super admins and developers could be creating content items without these roles. I have set the owner droplink to be required so we do not end up with items with missing owners.
Recommended links to send to the publishers
/sitecore/shell/Applications/Content Editor.aspx?fo= + contentItem.ID/?sc_mode=edit&sc_itemid=" + contentItem.ID
Comments