To configure Microsoft Flow, follow these steps:
- In a web browser, navigate to https://flow.microsoft.com.
- Sign in using your organizational account.
- Expand Data on the left, and select Connections.
- Click New Connection.
- Click the Search option, and type Service Bus. There will be one result; click the + symbol.
- Enter the primary connection string for the Service Bus queue (see the Get the primary connection string for the Service Bus section in the Creating an Azure Service Bus queue recipe).
- Press Create.
- Refresh the list, and select Edit from the ... button. Set the name to the Service Bus queue name (for reference), and paste in the primary connection string again.
- Select My Flows on the left hand list.
- Click New | Automated-from blank.
- In the Flow name, enter Process BOM Approval.
- Enter Service Bus in the Search all triggers text box.
- Select Service Bus - When a message is received in a queue (auto complete) - you may have to hover the mouse of the entry in order to see the full name.
- Press Create.
- For the queue name, press the drop-down list to select the Service Bus connection created earlier.
- Click New step.
- In the search box, type initialize variable, and then in the Actions list choose Initialize Variable.
- Enter BOMApprovalContent as the Name.
- Select String as the Type.
- Click the Value field, and then click on the option Content on the right-hand list that appears.
- In the search box, type Parse JSON, and select this option from the Actions list, shown as follows:
- In the Content field, click Add dynamic content and then select the BOMApprovalContent variable.
- We now need a schema. Open the business events form in SCM, locate the business event and click Download Schema, and copy the text into the paste buffer.
This is not a JSON schema, but a sample file that has all element defaults set to empty or zero.
- Now we have the text of a sample message, click Generate from sample, paste in the text, and press done, the result will be shown as follows:
- Click Save on the top right.
- Click My Flows on the left-hand list to see the list of flows again. On our flow, select the vertical ... button, and click on Run history.
- You should see an instance of the flow that ran, expand the Initialize variable block, and copy the contents of the Value field, this will look like the following:
{"BOMId":"D0001BOM","BOMLines":[{"BOMUnitId":"ea","ItemId":"M0001","Qty":1.0},{"BOMUnitId":"ea","ItemId":"M0002","Qty":1.0},{"BOMUnitId":"ea","ItemId":"M0003","Qty":1.0},{"BOMUnitId":"ea","ItemId":"M0004","Qty":1.0},{"BOMUnitId":"ea","ItemId":"D0002","Qty":1.0}],"BomName":"Mid-Range Speaker","BusinessEventId":"ConPIBOMApprovedBusinessEvent","ControlNumber":5637150576,"EventId":"C0D16056-46B0-4E4C-901B-AA25E84B3695","EventTime":"/Date(1560101558000)/","MajorVersion":0,"MinorVersion":0,"SiteId":"1"}
This was created when we tested the business event, and is a better example to use to generate the schema.
- Click Edit on the top right.
- On the Parse JSON step, click Generate from sample.
- Paste in the value taken from step 27.
- You should now see that the BOM Lines section is properly formatted.
- Save the flow.