Journey and Email Approval Process in Customer Insights - Journeys
Customer Insights - Journeys allows you to engage your customers throughout their relationship with your brand. Segments and activity triggers allow you to send personalized messages across channels to customers based on their needs at any point in time. You can use Customer Insights - Journeys to design personalized and engaging experiences for your customers and measure their impact on your business goals.
One of the Customer Insights - Journeys features some customers ask for is the ability to approve journeys and emails before they are launched or sent to their customers. This feature would help organizations ensure that your journeys and emails are compliant with brand guidelines, legal requirements, and quality standards. You can also collaborate with your team members and stakeholders by giving them feedback and suggestions on how to improve your journeys and emails.
This feature is not yet available as standard in Customer Insights - Journeys, but a custom approval process can be implemented as described in this post for your journeys and emails. You will need to have access to:
1. Plug-in Registration Tool to register the plug-in
- Download the Plug-in Registration tool by following the instructions in Dataverse development tools (Microsoft Dataverse) - Power Apps | Microsoft Learn
- Tutorial: Tutorial: Write and register a plug-in (Microsoft Dataverse) - Power Apps | Microsoft Learn
2. Visual Studio or similar tool to build the code
- Visual Studio 2017 (or later version)
- Knowledge of the Visual C# programming language
3. Privileges in Dataverse to register plug-ins
- Administrator level access to a Microsoft Dataverse environment
Approval process for Journeys
After you create a journey, the next step is to publish it so it can be executed. The settings tab on the Journey editor form can be extended to add custom fields. With this, you can add an ‘Approval’ field with different state values such as ‘In review | Approved | Edits required’ to create a hook for a plugin which can block the ‘Publish’ button until it is set to ‘Approved’. Below we walk through the steps to set this up.
Add field to Settings form
In our scenario, we are requiring the custom field “approved” to be set to yes to audit who approved the journey before sending it. Please review the documentation on ways to customize Customer Insights - Journeys forms Customize the Customer Insights - Journeys forms interface - Dynamics 365 Customer Insights | Microsoft Learn. In our example we are doing a simple UI extension. Please see below our suggestions:
1. Go to the Power Apps Portal (make.powerapps.com) and access Tables. In there, search for msdynmkt_journey in all tables.
2. After you open the Journey table go to Forms and open the Information main form.
3. Create a new field called Approved, define its data type to Yes/No and set it to simple behavior. In the example below it is set as business required field but that would be based on your business needs.
4. Go to the Tree View and access Settings. Expand Settings, select Form field in the toolbar and select the field you just created on previous step.
5. Save and Publish it. Congratulations! You have now added the Approve button to the journeys settings tab.
Create Validation plug-in
NOTE: In the following section, we would like to share a simple sample code that can be used AS IT IS but MUST BE TESTED in dev environment before it goes to production. Microsoft does not take any responsibility for any damage that can be caused if it is used without proper testing.
You will need to write a PreValidation plugin to block the ‘Publish’ button on the Journey form based on the custom approval field. This will be based on your business requirements.
The plug-in will be registered as Pre-Validation on Update of the statuscode field. It will check if the Approved column created in step 1 (test_approved) is also being updated and, if so, check its value. If the Approved field is not being updated, then we retrieve the PreImage that contains the test_approved column to check its value before the Update. In either scenario, if Approved field is No (false), an exception with a custom message is thrown, preventing the activation of the Journey to proceed.
var entity = (Entity)context.InputParameters["Target"];
// Journey Approval
if (entity.LogicalName == "msdynmkt_journey")
{
bool isApproved = false;
if (entity.Contains("test_approved"))
{
isApproved = entity.GetAttributeValue<Boolean>("test_approved");
} else if (context.PreEntityImages.Contains("PreJourney"))
{
Entity preJourney = context.PreEntityImages["PreJourney"];
isApproved = preJourney.GetAttributeValue<Boolean>("test_approved");
}
if (!isApproved)
{
throw new InvalidPluginExecutionException("Journey needs to be approved");
}
}
- Message: Update
- Primary Entity: msdynmkt_journey
- Secondary Entity: none
- Filtering Attributes: statecode, statuscode
- Event Pipeline Stage of Execution: PreValidation
- Image Type: Pre Image
- Name: Any
- Entity Alias: PreJourney (must match the name in the plug-in)
- Parameters: test_approved (must match the Approved column)
Depending on the business requirements you may want to send an email notification, so the approvers know there is a new journey pending approval. The approvers can then review the journey and approve, reject, or request changes. If the user tries to publish the journey without being approved an error message similar to the one below will appear in the toolbar.
Approval process for Emails
For Emails we have two options to implement an approval process. You have the chance to match the same user experience we shared for journeys above by adding the approval setting to the Settings pane or you can have a quick action available by creating a ribbon button. Both options will use the custom column to track the approval.
Add field to Settings form
In the first option, we are requiring the email to have a similar Approved switch like the one we suggested for journeys. Please see below our suggestions:
1. Go to the Power Apps Portal (make.powerapps.com) and access to Tables. In there, search for msdynmkt_email in all tables.
2. After you open the Email table go to Forms and open the Email Header form.
3. Create a new field called, for example, Approved, define its data type to Yes/No and set it to simple behavior. In the example below it is set as business required field but that would be based on your business needs.
4. Go to the Tree View and expand Email header - [Label blank] - Section, select Form field in the toolbar and select the field you just created on previous step. Save and Publish.
5. Now go back and this time open the email Information main form (the customizable version) and add the same custom field to [Label blank] layer. If you add to any other section it will fail to work in UI.
In the second option, we are creating a new button in the email ribbon. Please see below the suggested steps:
1. Go to the Power Apps Portal (make.powerapps.com) and access to Apps. In there, search for Customer Insights –Journeys and click on Edit.
2. Make sure you load the Real-time journeys pages. Scroll down until you find Channels page. Select Emails View and select Edit command bar option - Edit.
4. For our scenario we are creating a button named Review Email with three options: Approved, Rejected and Check Approval Status.
5. Create a new Dropdown called Review Email. Within the dropdown component create a new command and name it Approved. On the action select to run formula and add the following: Patch(Emails,Self.Selected.Item,{Approved:true}); Notify("Approved")
Repeat the action but this time adding a command named as Rejected. On the action select to run formula and add the following: Patch(Emails,Self.Selected.Item,{Approved:false});Notify("Rejected")
Now you just need to create the third command to check approval status. If you have added the field to the Form you might not need this button as you can verify the Approval status in the Form. On the action select to run formula and add the following: Notify(If(Self.Selected.Item.Approved, "This Email has been Approved", "This Email has not been Approved"))
Save and Publish it.
Open Customer Insights –Journeys app and create a new email in Real-time journeys. You will see the new button in the toolbar like below:
Regardless of the path you chose, on the next step you will need to write a PreValidation plugin to block the Ready to Send button based on the custom approval field. This will be based on your business requirements.
NOTE: In the following section, we would like to share a simple sample code that can be used AS IT IS but MUST BE TESTED in dev environment before it goes to production. Microsoft does not take any responsibility for any damage that can be caused if it is used without proper testing.
Note that the code is very similar to the one for Journeys, only changing the entity name (msdynmkt_email instead of msdynmkt_journey), the name of the Pre Image (PreEmail instead of PreJourney), and the error message.
//EmailApproval
if(entity.LogicalName == "msdynmkt_email")
{
bool isApproved = false;
if (entity.Contains("test_approved"))
{
isApproved = entity.GetAttributeValue<Boolean>("test_approved");
}
else if (context.PreEntityImages.Contains("PreEmail"))
{
Entity preEmail = context.PreEntityImages["PreEmail"];
isApproved = preEmail.GetAttributeValue<Boolean>("test_approved");
}
if (!isApproved)
{
throw new InvalidPluginExecutionException("Email needs to be approved");
}
}
In the Plug-in Registration, add the Step with the below values. You can leave the remaining values as default.
- Message: Update
- Primary Entity: msdynmkt_email
- Secondary Entity: none
- Filtering Attributes: statecode, statuscode
- Event Pipeline Stage of Execution: PreValidation
After adding the step, a Pre Image will need to be added by right-clicking on the created step and selecting Register New Image. Fill out the information as follows:
- Image Type: Pre Image
- Name: Any
- Entity Alias: PreEmail (must match the name in the plug-in)
- Parameters: test_approved (must match the Approved column)
As we described for journeys depending on the business requirements you may want to send an email notification, so the approvers know there is a new email pending approval. The approvers can then review the email content and settings and approve, reject, or request changes.
If the user clicks on the Ready to Send button without the approval an error message similar to the one below will appear in the toolbar. The error message can be personalized based on the business requirements.
Once the email has been approved, it will be ready to be used on any journey. You can track the approval requests from the approval column in the emails view.
Congratulations! You have successfully implemented an approval process for emails and journeys in Customer Insights - Journeys.
*This post is locked for comments