A hands-on scenario - Automatic invoice processing by Power Automate Cloud Flow and Desktop Flow

Hi, my name is Yuto Kawabata, GBB Technical Specialist at Microsoft.


In this hands-on I will go through how we can automate and make our processes efficient by utilizing Power Automate Cloud Flow and Desktop Flow in an approval scenario.
Let me pick up a use case for how to automate approval seeking from manager and invoice processing as shown a slide image below.

<iframe src="//www.slideshare.net/slideshow/embed_code/key/5hcHW4SzWbMLT" width="595" height="485" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;" allowfullscreen> </iframe> <div style="margin-bottom:5px"> <strong> <a href="//www.slideshare.net/YutoKawabata/automatic-invoice-processing-by-power-automate-cloud-flow-and-desktop-flow-en" title="Automatic invoice processing by power automate cloud flow and desktop flow en" target="_blank">Automatic invoice processing by power automate cloud flow and desktop flow en</a> </strong> from <strong><a href="//www.slideshare.net/YutoKawabata" target="_blank">Yuto Kawabata</a></strong> </div></iframe>


#1.Premises
1.	Click the link below and log in with your user id/email address.
https://flow.microsoft.com/
 ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/381a0d24-aa8a-63a0-f0f3-6d64acb2a7c8.png)

2.	The screen will look like this.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/0fabf33d-d054-1102-0976-d042d23407bf.png)

#2.Create an Approval Process by Cloud Flow
Go to https://flow.microsoft.com/

Select "Automated cloud flow" as below.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/7ee73a5e-8837-0e3a-4c98-c0f6b1e269d0.png)

Then a new pop-up window will appear.
Select "When a new email arrives(V3)". You can set the name of the Flow to whatever you like, e.g. Automatic invoice processing.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/b2e91ae6-37a7-840b-3b5f-1ea2e9814678.png)

Then click on "Create".
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/99bfa9ed-e5a4-13ab-9bed-5c9291e3c888.png)

*If you are new to the operation described above, you would need to make sure that you have authentication setting for Outlook connector first.
*If you get any popups/instruction tips for first time users appear, you can dismiss them or proceed upon your preference.

For convenience, in this scenario please set your email address in "From" setting.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/da43c4d5-3dd8-3b01-66be-f617f9739b74.png)

Click on "+ New step" to add to the process.
You can search by "approval" and select "Start and wait for approval"
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/46089ea8-ec7e-21c3-45cb-3a7c04cf9eb1.png)

Then you can select the approval type option. Select "Approve/Reject - Everyone must approve"
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/344f3d18-27c4-d25d-4e38-5408cbd6cb5f.png)

You can set the title to anything you like, for example "Approval Request". Add "Assigned to" by selecting Dynamic content you can specify contents from previous trigger/actions.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/86777440-5933-65e2-aa75-d5fb92f4bf4d.png)

In Details section you can specify "Body" from the Dynamic content selection.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/6d6c8774-9d62-af67-41a2-199669404bdd.png)

The "Approvals" action takes around 5 minutes to prepare its database when it comes to run only for the first time creation in Power Automate. Try to run a prompt flow including this action tentatively.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/e5ae0c85-e3b9-081d-edcc-60ec2630630a.png)

For utilizing "Approval" action first, you can add "Terminate" Control and specify "Succeeded" in the Status option.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/864bc2bb-fada-78c7-5693-1090b8fc5b1d.png)

Please try to send an email with a body text below for instance. You can utilize below by copy & paste in your Outlook email body (the body should be in a format of Text, not HTML in Outlook email).

```
2021/10/12 9:46:14
〇〇 Corporation
marumaru@corporate.com
$100,000
Unclaimed
```

Now you can see the running status successfully in a history log (it would take some minutes to get reflected until when you create the first approval trigger) and you get notification like below to get your approval (Please feel free to try Approve or Reject here).

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/3325c16a-1cbc-83c6-c066-dd15888dc5a3.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/ab5b1fd3-86bf-333e-f743-462cbe07b756.png)

I hope it works now in your environment!

Add Condition in Control in between the "Approval" and "Terminate" actions.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/dfbb50f5-778d-c23a-f1c3-9eb4e4d2de94.png)

Specify Condition in Control action.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/2ee17014-efba-0f7d-49b1-a044817e0a23.png)

Now you can see 2 condition branches, "If yes" and "If no".
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/3f5ffb41-b700-7356-dd22-2508acef56b4.png)

Populate "Outcome" in a dynamic value and "Approve" as a direct inputted text in a condition of "is equal to".
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/f3649a1b-0d87-9a3a-c4dc-276907ec2be3.png)

Add a Teams action
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/f6c38a32-e075-fadd-e755-9272224813fc.png)

Select "Post message in a chat or channel".
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/d72411de-f789-6407-c67a-7acbc394e556.png)

Populate items like below.
Post as：Flow bot
Post in：Chat with Flow bot
Recipient: From (a dynamic content)
Message: To (a dynamic content) approved this request; Body (a dynamic content)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/15af2d22-9293-8dae-56f7-4eda7c3692d1.png)

Similarly you can set a condition branch of "If no", let you select "Copy to my clipboard" and duplicate the content from one branch to another. 
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/3086581d-c5de-208c-1959-bcca249f4723.png)

In order to copy the condition of Teams please select "My clipboard" and the copied action content as below.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/90b916c3-711d-be44-0c02-79b8e09358e5.png)

Edit items similar to the copied part like below.
Post as：Flow bot
Post in：Chat with Flow bot
Recipient: From (a dynamic content)
Message: To (a dynamic content) **denied** this request; Body (a dynamic content)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/3a1fecf3-9f1d-d560-3659-f562c7a351da.png)

Let's check how it works when your manager (now you can make yourself as an approval for the testing convenience).

The overall settings now should be like below.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/49fa7f79-42df-8f03-3cd1-cd288bb47a07.png)

#3.Create a Desktop Flow to input data to legacy application automatically ※RPA license for Power Automate for desktop needed
###Premises for Desktop Flow; Applications to set up
- Latest version of Power Automate for desktop:
    - https://powerautomate.microsoft.com/en-us/desktop/
- Contoso invoicing app (an "official" legacy application provided by Microsoft)
    - Provided in a RPAinaDayPackage here: https://powerautomate.microsoft.com/en-us/blog/announcing-microsoft-rpa-in-a-day-version-2/
    - Or you can download from my GitHub link below.
        - https://github.com/YutoKa/sample/raw/main/Contoso%20Invoicing%20App.zip

###Create a Desktop Flow
Create a new desktop in your client PC env. I will name the cloud flow "Invoicing data input from cloud flow".
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/824530c0-a5be-8316-cc47-20a7b20178ba.png)

Add Input/output variables in + button on the right menu.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/addb7f62-fb3c-29b0-ff9f-9a4ef013044b.png)

Proceed it in default setting for Input variable from the cloud flow.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/2f0aef9a-ca09-b1df-82ca-382de18db55d.png)

Add "Split text" action first.
- Text to split：%NewInput%
    - You can specify this from {x} button set by Input variable.
- Standard delimiter: New line
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/424880c3-d1c1-60cd-96e9-448c3da754ac.png)

Now you could split the lines of below by new lines.

```
2021/10/12 9:46:14
〇〇 Corporation
marumaru@corporate.com
$100,000
Unclaimed
```

- TextList[0]
    - Populate first item of the list, such as "2021/10/12 9:46:14".
- TextList[1]
    - Populate second item of the list, such as "〇〇 Corporation".
- TextList[2]
    - Populate third item of the list, such as "marumaru@corporate.com".
- TextList[3]
    - Populate fourth item of the list, such as "$100".
- TextList[4]
    - Populate fifth item of the list, such as "Unclaimed".

You can set the desktop flow as you like, here is one of examples.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/94158940-4637-c536-7c0c-4cd1f002cd1f.png)

###Add an action of Desktop Flow in Cloud Flow

In order to communicate from Cloud Flow to Desktop flow, please add an action of desktop flow which you created in the previous section.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/0a883353-07ac-c3f8-38b9-a2f605a2a121.png)

Select the desktop flow which you created just now.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/351bc704-0602-4084-3d13-e56c5be56325.png)

Populate items as below
- Desktop flow: Specify the created flow name.
- Run Mode: Attended
- NewInput: Body (a dynamic content)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/808554/2b0deee0-b139-a036-c6d5-819b7528b15f.png)


#4.Let's run the overall process and check how it goes.
<iframe width="560" height="315" src="https://www.youtube.com/embed/Z8yZn2kPeGY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>