Social Post Approvals in Dynamics Marketing Option 2: Flow from a Business Process Flow
Marketing is an art, there is no ‘right’ way to do it and every company is different. What works for one organisation will not necessarily work for another. However, what many have in common is a need for marketing activities to be reviewed and approved by relevant managerial parties before being thrown out to the world. Many enterprise level Marketing solutions have this functionality built in out of the box,
Unfortunately in Dynamics Marketing it is not so simple… Microsoft announced as part of release wave 2 2019 “Support approvals using power automate” which got me all excited about this functionality being available. However the interpretation of ‘support’ was rather loose, the documentation [1] provides instructions on how to set this up. The documentation lives in the ‘Developer Guide’ section and requires custom buttons, entities, JavaScript and ‘extensibility points’ (whatever they are!?).
I broke my ‘ABC’ rules and spent months stabbing around trying to getting this working. Along the way I learnt a lot, built my first functioning custom button and JS, somewhat successfully built a very flaky solution which achieved about 20% of the solution then realised there must be an easier way to do this.
Fortunately Power Automate has some really awesome approval functionality and the ability to trigger Instant flows from business process flows in Dynamics is in public preview. Whopeee! Lets go build a delightfully low code approvals process in Dynamics Marketing.
Business Process Flow
So lets start with a Business Process Flow, a few new fields to set the Approver plus capture their response and additional comments and some additional values on the Status field to accommodate ‘Pending Approval’ & ‘Approved’.
I used a real time workflow to automatically populate the Approve as users manager however this could easily be self selected or controlled to a select list of "‘Approvers’ with some further customisation.
Don’t forget to add your BPF to the Dynamics Marketing app otherwise it won’t be available to run and you will be left baffled for hours as to why on earth not!
JavaScript & PCF
In addition to the Business Process Flow I wanted to help guide the user approval experience a little more by introducing a really cool PCF control [2] which displays pulsing notifications in Dynamics to show the user the current status of the Social Post.
Confession: I used some very badly written JavaScript here because after the traumas of trying to create a custom flow calling button (post of this to follow) I wanted to show off my snazzy new ‘coding’ skills plus its looks really cool. I added a new field to store the notification text then with the help of some JS On Load & On Change I was able to trigger the notification updates throughout the process like so.
this.attributeOnChange = function (executionContext) {
var formContext = executionContext.getFormContext();
var StatusReason = formContext.getAttribute("statuscode").getValue();
var PostState = formContext.getAttribute("msdyncrm_poststate").getValue();
var SchedDate = formContext.getAttribute("msdyncrm_startdate").getValue();
if(StatusReason == 277240000){
var message = "This post is pending approval";
formContext.getAttribute("aeh_statusnotification").setValue(message);
}
if(StatusReason == 2){
var message = "Social post approval required";
formContext.getAttribute("aeh_statusnotification").setValue(message);
}
if(StatusReason == 277240001 && PostState != 270100001){
var message = "Social post approved - select Post or Schedule";
formContext.getAttribute("aeh_statusnotification").setValue(message);
}
if (PostState == 270100001){
var message = "Social post scheduled for : " + SchedDate;
formContext.getAttribute("aeh_statusnotification").setValue(message);
}
formContext.data.entity.save();
}
Power Automate
Once the Post has been defined with a channel, account and content the user can send the post for approval. Capturing their proposed posting date and also any additional comments to send to the approve.r.
Here we could use Power Automate to automatically can trigger the BPF to move to the next stage ‘Approve’ and await the managers response, but rather than reinventing the wheel I will leave you with a link to a blog/video from Elaiza Benitez which explains it beautifully [5]. The users manager is then sent an approval email which provides all the information about the social post right there without even having to go into Dynamics Marketing. The user can approve/reject and send back additional comments accordingly.
So what if the manager doesn’t respond? Are we stuck in ‘Approval Requested’ forever? Of course not! Using a handy blog from Daniel Laskewitz aka Office365 Dude [3] I have set the approval to time out the approval request after 3 days. In this scenario the parallel branch is triggered ‘on timeout’ and the requester will be notified by email.
The approval is then consequently cancelled to avoid the manager still ‘seeing’ the approval in their approvals inbox. I’m taking some inspiration from Brain Dang. Yes its a horrible workaround but I am building with positivity - Microsoft will build the ability to easily cancel approvals sometime in the near future.
Back to the ‘happy path’ - our manager actually responds in a timely manner to the request. Once rejected or approved the social post is updated, the user is notified via email of the outcome and they are again given clear indication on next steps - either schedule or post now.
Should the user choose schedule then existing Dynamics Marketing functionality (magic) automatically triggers the post as per the schedule defined and there you have a wonderful social post approval process without only a teeny bit of ‘real code’ - hurah!
Although this scenario focuses on Social Post approvals (because I’m such a hip, young and cool social media buff (not!)) the concept could easily be applied to other areas such as Customer Journeys & Marketing Emails
Side note: I will openly admit this is not production ready, it would benefit from some little bit of coding magic for two reasons. Both reason I’m sure neither of which are rocket science however Rome wasn’t built in a day and I’m going to leave that to the magical developers to do.
1) disable the Post/Schedule buttons before the post is approved
2) make it ‘god mode proof’ by enforcing approver security beyond the client side
Finally - the flow behind all this magic in its full glory - please comment below or contact me with any questions, feedback or suggestions. I would love to hear from you
A few though nuggets/closing comments…
Afew times when tweaking the flow and using the test using previous run I experienced this error. To fix this you need to trigger manually from BPF again rather than using test re-runs - happy flowing!
Cool things to add? Use the proposed date and time for the post to then set a conditional timeout the approval so that if the proposed date is in the past - the approval should expire and be sent back to the requester to review/follow up.
Article References
[1] Build an approvals feature in Dynamics Marketing developer notes https://docs.microsoft.com/en-us/dynamics365/marketing/developer/marketing-approvals-feature
[2] PCF Gallery https://pcf.gallery/pulsing-notifications/
[3] Timeout approvals https://www.o365dude.com/2018/06/02/timeout-flow-approvals/
[4] Update BPF stage in a flow https://benitezhere.blogspot.com/2019/05/automatically-update-the-stage-of-a-business-process-flow-with-flow.html