Monday, 3 June 2019

Automatically update the stage of a Business Process Flow with Flow 2.0

22:26 Posted by Benitez Here , , , , , No comments
From my last WTF episode:

I decided to use two Compose actions because I don't know how to store the Dynamics 365 API request in a Flow action. If you know how to do this, feel free to blog and tweet to me so that I can check it out.

I heard back from two people, hooray!

The first person I heard from was David Yack, he was wondering why I had chosen my uncanny method when really I could achieve the same outcome using the List Records action. When he explained it I was thinking to myself, hmmm... 🤔 oh... YEAH!!! It was so obvious only after hearing it from him haha. Like any other person who goes through the process of solution design - sometimes the answer is staring at you the whole time.

The second person I heard from was Yasir Safeer who I currently work with. He was going to suggest another method however I mentioned I already heard from David. However, he gave an awesome tip which made me go, really?! I tried it and to my surprise it worked.

This WTF episode talks about the two improvements I made to my Flow thanks to David and Yasir
#iAppreciateYou 🙏

Using a CDS List Records action

My Flow trigger is when the status reason of the Application has been updated. Next, I was using a CDS List Records action that would retrieve the Application Business Process Flow record so that I could identify the  associated Process Stage ID.

Rather than storing the Review stage ID and the Approved stage ID in two Compose actions after calling the API request in a separate browser using the Process stage ID, I can simply use the CDS List Records action against the Process Stage entity. I was able to use a filter query from David's suggestion that would only return the Process Stage record that had the stage name of "Review."


It's so funny to me because it was staring at me when I was reviewing the API request. It clearly tells you the entity to reference and the field as well. Thanks David for showing me way 😁 It was not obvious at the time but now it is.

I then applied a Parse JSON action where I used the first function. 

first(body('1.4.1_Get_Process_Stage_Review_record')?['value'])


I'm only after after a single record and the first function prevents the Apply to Each from appearing downstream in the Flow. I am using the properties later on in the Flow. I briefly covered the first function in another previous WTF episode so take a look when you can.

I applied the same methods for the Approve stage however what you'll see differently this time is that I am using parallel branching. Parallel branching is useful when you have actions that can be executed that are not dependent on the previous action or each other. Since I am retrieving the stage IDs through the List Records action both actions can run at the same time.

Changes to the last action

My very last action in the Flow is updating the Application Business Process Flow record. In the Active stage field of the action I am referencing the stage ID through the Parse JSON action. Previously I was achieving this through my two compose actions.


The cool tip that Yasir shared with me is that you don't need to update the Traversed Path value. I was puzzled because I followed what was in the docs.microsoft.com article but I trust Yasir's advice given that he's an awesome consultant so I gave it a go. I cleared my previous expression and left it blank.

Flow in action

When you submit an Application, the Flow succeeds as I expected.


When there are two approvals (one from the External Reviewer and the other form the Internal Reviewer) the Flow succeeds as I expected.


In both use cases the traversed path correctly updates. Amazing. Thanks Yasir, good tip man.

Summary

By using a CDS List Records action against the Process Stage entity, it will allow you to reference to the stage IDs of your Business Process Flow entity. You also don't need to use an expression to update the Traversed Path field either, it magically works 🧙‍♂️

My WTF Flows is available for download on the TDG Power Platform Bank.

Till next time, toodles.

0 comments:

Post a Comment