D365 Business Central, Power Automate

Business Central Power Automate Document Approvals – Comments 📝

When a Power Automate document approval is enabled for Business Central we can leverage the approvals connector or another platform. In either of those scenarios then comments an approver makes will be between the requester and the approver. Now in most scenarios this is fine. However, if we compare this to standard OOTB document approvals for BC then we get all the comment history….so why should we settle for less just because we’ve adopted a different platform for approvals? Plus, the fact the approver for Power Automate doesn’t have to be a BC user means we have no real grasp on who approved. Couple this with the fact the user assigned to the Power Automate BC connector shows as the “approver” in BC

Looks like a self approval to anyone in BC – but it won’t have been 😬

Now to cater for many we will need something to enable the logging of comments across all possibilities. So, I’m talking Sales, Purchase, Customers, Vendors and Items – all of these areas can have approvals in Power Automate for BC. All of them have a standard “Comments” table which can be used as well. Looking to avoid the standard approvals comments because the page action doesn’t exist when you use Power Automate BC Document approvals:

Instead I will use the regular “Comments” area for each piece of data:

There are many ways, like always, to solve this but I’m opting for the quickest. Which of course means, I considered creating a codeunit to act like a broker for each comments area. However, when you can it is great to use all standard objects and tools! For instance if you’re not familiar with “Page Inspection” check it out. I used it to determine the page numbers for all the areas I need to eventually cover: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-inspecting-pages?tabs=page

Simply a case of publishing three pages as web services:

So what kind of data do we have to send to the service so it attaches to the correct record? I will bundle together Customer/Vendor/Item as the protocol is the same you just swap out the table number. Sales and purchase we’ll handle separately.
       //Customer, Vendor or Item can use a minimum JSON body of the below. Just swap out the "Table_Name" and "No"
       {
            "Table_Name": "Item",
            "No": "1896-S",
            "Comment": "Test"
        }

       //Purchase Documents just swap out the "Document_Type" and "No"
       {
           "Document_Type": "Invoice",
           "No": "107209",
           "Document_Line_No": 0,
           "Comment": "Test Comment"
       }

       //Sales Documents just swap out the "Document_Type" and "No"
       {
          "Document_Type": "Invoice",
          "No": "107209",
          "Document_Line_No": 0,
          "Comment": "Test Comment"
       }

So, that’s BC organised, what about Power Automate? I have opted for a OOTB BC template Purchase Invoice approval in Power Automate. The posting of comments, for me at least, can go in two possible places. One is right after the “Start an approval” action

Or you could place them after the condition so that you can add more context to the comment. In my case I’ve use a concat() function to add an emoji

Here is the result:

Minor draw back of using the standard tables/pages here is that the comments table(s) could well be editable to the user. It is reasonable that permissions can control this as the user who posts the comment is the one assigned to the BC Power Automate connector. Of course, permission sets aren’t the only standard choice. You could use change log or field monitoring too. If that doesn’t sit well with you then I’d suggest adding a boolean field to control whether the comment record can be altered or not. You can add that to the JSON body you send once it’s available. Final thing being the “Comment” field in the standard tables only houses 80 characters – but that’s the same as the standard BC approvals comment field – so no essay long approval comments folks 😜