Build Connected Field Service processes and automations

Completed

Dynamics 365's Connected Field Service solution lets you remotely monitor IoT enabled devices to keep track of up time, device statistics, anomalies and more. After an IoT Device communicates an anomaly or exception, that information is sent to Connected Field Service as an alert. Once the alert is captured, we can use Dynamics 365's ability to create automation and business process to develop automated processes for acting on, routing, and fixing the issues.

The purpose of this hands-on-lab is to introduce you to building and automating Connected Field Service processes, and demonstrate how these items can be used as part of an overall IoT solution.

Scenario

You work for a plumbing and heating company that sells and services smart home devices. Since many of the devices that you service are smart devices, information from those devices can be captured remotely to aid in the servicing of that equipment. Your organization has several defined scenarios and processes that they use while servicing equipment. These processes can vary depending on several factors including:

  • Type of device in need of service

  • Severity of the issue detected

  • Age of the device

  • Location of the device

  • Availability of resources to work on a specific device

The above items represent only a small portion of factors that your organization uses to determine the process for servicing equipment.

Lately, you have been installing many smart thermostat devices. These devices have been handy in being able to track temperature and humidity readings in areas when it's important to maintain a consistent temperature and humidity. Now because you have more information available, it has forced you to create new processes for handling and resolving issues reported by these devices. The first area you would like to focus on automating is the process used for temperature related issues.

Your organization is looking to implement the following process:

  • If a device detects a temperature reading of more than 70 degrees, an alert should be surfaced in your Connected Field Service environment.

  • If the temperature reading is between 70 degrees and 85 degrees, a command should be sent to remotely reset the device to see if the issue resolves itself.

  • If the temperature reading is between 86 degrees and 100 degrees, a service agent should be able to create a case to attempt to resolve the issue.

    • If the service agent can't resolve the issue, a work order should be created, and an on-site technician should be scheduled for the item.
  • If the temperature reading is more than 100 degrees, it's considered a potentially catastrophic event. A work order should be created, and an on-site technician should be scheduled for the item.

Exercise - Automate and customize

Before you begin: This exercise assumes that you already have a working Connected Field Service deployment that is connected to either an Azure IoT Hub or an IoT Central instance. If you don't have a Connected Field Service environment available, it's recommended that you take the Introduction to Connect Field Service Module. That module helps you to set up and configure a Connected Field Service environment.

Task - Create a new IoT alert process solution

In this first task, we create a Dynamics 365 solution that we can use for storing all the customizations and processes that we create in this module. Not only does this make it easier for us to potentially transport these customizations later, but it also helps with cleaning up our environments after you complete the course.

  1. Navigate to Power Apps and make sure you are in the correct environment.

  2. Select Solutions and select New Solution.

  3. Name the solution IoT Alert Processes.

  4. Select the Publisher drop down and select Publisher.

  5. Configure the Publisher as follows.

    • Display Name: Connected Field Service Course

    • Name: Connected Field Service Course

    • Prefix: cfs

  6. Select Save.

  7. Select the Publisher dropdown and select the publisher you created.

  8. In the Version field, enter 1.0.0.0. and select Create.

  9. Select to open the IoT Alert Process solution you created.

  10. Select Add Exiting and select Table.

  11. Select the Case, IoT Alert, and Work Order and then select Next.

  12. Select Include All Objects for all three tables and select Add.

Task - Customize the IoT alert table

To help with automating items and actions based on IoT alerts, we need to be able to extract specific information for generated IoT alerts. We can query it and trigger items based on that data. Since the alert data contains only a JSON string that contains all the data, we need to create some other fields on the IoT alert table. We can use it to send specific data into and build queries off those fields.

  1. Make sure you're still in the IoT Alert Processes solution.

  2. Select to open the IoT Alert table.

  3. Select the Columns tab and select New Column.

  4. Enter Reading for Display Name, select Whole Number for Data Type, and select Advanced Options.

  5. Enter 0 for Minimum Value, 250 for Maximum Value, and select Save.

  6. Repeat the process to add these columns:

    • Threshold

      • Display Name: Threshold

      • Data Type: Whole Number

      • Minimum Value: 0

      • Maximum Value: 250

    • Reading Type

      • Display Name: Reading Type

      • Data Type: Yes/No

      • Change the No value to Temperature

      • Change the Yes value to Humidity

      • Default choice: Temperature

    • Rule Output

      • Display Name: Rule Output

      • Data Type: Single Line of Text

    • Customer

      • Display Name: Customer

      • Data Type: Lookup

      • Target Record Type: Account

  7. Using the breadcrumbs, select IoT Alert.

  8. Select Relationships under Schema.

  9. Select New Relationship and select One-to-Many.

  10. Select Case for the Related Entity, enter IoT Alert for Lookup Column Display Name, and select Done.

  11. Select the solutions name.

  12. Select Publish all customizations and wait for the publishing to complete.

  13. Select the ... button and select Switch to classic.

  14. Expand Entities, expand the IoT Alert entity, and select 1: N Relationships.

    Screenshot of the Case to IoT Alert relationship.

  15. Select Mappings and select New.

  16. Configure the mapping from the list as follows and select OK.

    • Source Entity Field: cfs_customer

    • Target Entity Field: customerid

  17. Select Save and Close.

  18. Select Publish all customizations and wait for the publishing to complete.

  19. Close the solution explorer.

Task - Create a flow to populate values

Now that we have the field available to store the data that we need, we next need to populate those fields with the correct data. To do so, we're using some of the JSON-based field value actions that are included in the Connected Field Service solution. We create a flow that executes a JSON-based field value action, to extract a specific piece of data from the alert data field. Then we populate that data to one of the fields we created in the previous task.

  1. Navigate to Power Apps and make sure you are in the correct environment.

  2. Select Solutions and select to open the IoT Alert Processes solution.

  3. Select New and select Automation > Cloud Flow > Automated.

  4. Set the Flow Name to Populate Alert Fields.

  5. Search for Microsoft Dataverse and select Dataverse. Make sure that you have selected the Green Dataverse Connector.

  6. Select When a Record is Created, Updated, or Deleted, then select the Create button.

  7. Select Added for Trigger Condition, IoT Alerts for Table Name, select Organization for Scope and select New Step.

  8. Search for Parse and select Parse Json.

  9. Select the Content field and select Alert Data from the Dynamic Content pane.

  10. Paste this Json schema in the Schema field and select + New Step.

    {
        "type": "object",
        "properties": {
            "deviceid": {
                "type": "string"
            },
            "readingtype": {
                "type": "string"
            },
            "reading": {
                "type": "integer"
            },
            "eventtoken": {
                "type": "string"
            },
            "threshold": {
                "type": "integer"
            },
            "ruleoutput": {
                "type": "string"
            },
            "time": {
                "type": "string"
            }
        }
    }
    
  11. Search for Update a Row and select Update a Row. Make sure that you have selected Green Dataverse Connector.

  12. Rename the step Update Alert.

  13. Select IoT Alerts for Entity Name, select the Row ID field and select IoT Alert from the Dynamic Content pane.

    Screenshot of IoT Alert in the Dynamic Content pane.

  14. Select Show Advanced Options.

  15. Select the Reading field and select reading of the Parse Json step in the Dynamic Content.

    Screenshot of reading under Parse JSON.

  16. Select the Reading Type field and select Enter Custom Value.

  17. Select the Expression tab, paste this expression, and select OK. Make sure Parse_JSON matches the Parse Json step name.

    if(equals(body('Parse_JSON')?['readingtype'], 'Temperature'), false, true)
    

    Screenshot of expression pasted in the Expressions tab.

  18. Select the Rule Output field and select ruleoutput from the Parse JSON action in Dynamic Content pane.

  19. Select the Threshold field and select threshold from the Parse JSON action in Dynamic Content pane.

  20. Your completed Flow should resemble this image:

    Screenshot example of the completed Flow.

  21. Select Save.

  22. DO NOT close this page.

Task - Add the remote reset flow steps

Now that we have extracted the correct data and placed it in the correct fields, we need to add new steps to the flow. These steps determine the temperature value in the reading field. If it falls between 71 degrees and 85 degrees, it should automatically create an IoT device command that performs a device reset, and send it to the device.

  1. Go back to the flow and select New Step.

  2. Select Condition.

  3. Select the Choose Value field and select Reading from the Update Alert step in the Dynamic content.

    Screenshot of Reading selected under Update Alert.

  4. Select is greater than or equal to.

  5. Enter 71 for Value, select Add, and select Add row.

    Screenshot of the Reading value set as 71 and the Add row feature.

  6. Select the Choose Value field and select Reading from the Update Alert step in the Dynamic Content.

  7. Select Is Less than or Equal to.

  8. Enter 85 for Value.

  9. Your condition should now look like this image.

    Screenshot of what the condition should now look like.

  10. Go to the Yes branch and select Add an Action.

  11. Search for Add a new row and select Add a new row.

  12. Rename the step Create Reset Command.

  13. Select IoT Device Commands for Table Name, select the Name field and select Description from the When a record is created, updated or deleted action in the dynamic content.

    Screenshot of IoT Device Description from When a record is created, updated, or deleted.

  14. Add Device Reset to the Name and select Show Advanced Options.

  15. Select the Customer Asset field and type msdyn_customerassets().

  16. Place your cursor between ( and ) and select Customer Assets (Value) from the When a record is created, updated or deleted action in the dynamic content.

    Screenshot of the Customer Asset (Value).

  17. Select the Device field and type msdyn_iotdevices().

  18. Place your cursor between ( and ) and select IoT Device (Value) from the When a record is created, updated or deleted action in the dynamic content.

    Screenshot of the Device (Value) highlighted.

  19. Select the Primary Alert field and type msdyn_iotalerts().

  20. Place your cursor between ( and ) and select IoT Alert from the Update Alert action in the dynamic content.

    Screenshot of the Iot Alert highlighted.

  21. Paste this JSON in the Message field.

    {"CommandName":"Reset Thermostat","Parameters":{}}
    

    Screenshot of the JSON pasted in the Message field.

  22. Select Hide Advanced Options.

  23. Select Add an Action.

  24. Search for Update a Row and select Update a Row.

  25. Rename the step Deactivate Alert.

  26. Select IoT Alerts for Table Name, select the Record ID field and select IoT Alert from the Update Alert action in the Dynamic Content.

    Screenshot of the IoT Alert highlighted.

  27. Select Show Advanced Options.

  28. Locate the Status field and set it to Inactive.

  29. Select Hide Advanced Options.

  30. The new part of the flow should now look like the image.

    Screenshot of the new part of the flow.

  31. Select Save.

Task - Modify the CFS - IoT alert process flow

Currently we're using a business process flow called CFS - IoT Alert Process Flow to guide users in resolving an alert when it's triggered. When a temperature reading is between 86 degrees and 100 degrees, in the business process we should create a case record. Then create a work order if we can't resolve the case. If the temperature reading is above 100 degrees, the business process should skip the case stage all together and go straight to work order. In this task, we're modifying the CFS - IoT Alert Process Flow to reflect these specific needs.

  1. Navigate to Power Apps and make sure you are in the correct environment.

  2. Select Solutions and select to open the IoT Alert Processes solution.

  3. Select Add Existing and select Automation > Process.

  4. Search for CFS, select CFS - IoT Alert Process Flow and select Add.

  5. Open the CFS - IoT Alert Process Flow.

  6. Select the Deactivate button to deactivate the process.

  7. Confirm deactivation.

  8. Expand Details on the IoT Alert Created stage.

    Screenshot of expanded details on the IoT Alert Created stage.

  9. Under Components, drag the Data Step below the Alert Time step.

  10. Configure the Data Step as follows:

    • Step Name: Reading

    • Data Field: Reading

  11. Select Apply to save your changes.

  12. Repeat steps 9 - 11 to add the following Data Steps to the IoT Alert Created stage:

    • Threshold

    • Reading Type

    • Rule Output

  13. Select the Components tab, drag the Condition component to the right of the IoT Alert Created stage.

    Screenshot of the Components tab with the Condition component to the right of the IoT Alert Created.

  14. In the Condition Display Name, enter Temperature Condition.

  15. Configure Rule 1 as follows:

    • Field: Reading

    • Operator: Is greater than or equal to

    • Type: Value

    • Value: 86

  16. Select the New button to add another rule.

  17. Configure Rule 2 as follows:

    • Field: Reading

    • Operator: Is less than or equal to

    • Type: Value

    • Value: 100

  18. Ensure the Rule Logic is set to And.

    Screenshot of the Rule Logic set to And.

  19. Select Apply

  20. Select the Temperature Condition Stage, select the Connector Icon, from the menu that appears, select Reconnect.

  21. Select the Create Work Order stage as the 2nd Point.

  22. Your business process flow should now resemble the image:

    Screenshot of the business process flow.

  23. Select Save and Activate the CFS - IoT Alert Process Flow.

  24. Close the Process editor browser window or tab.

  25. Select Done on the previous window for the Solution.

  26. Select Solutions and select Publish All Customizations.

Task - Test your newly created automation

Now that we can create the necessary customizations, flow, and business process flows we use a simulator to test everything to ensure that it's performing the desired functionality.

  1. Navigate to Power Apps and make sure you are in the correct environment.

  2. Select Customer Assets and select the New Button.

  3. Enter Start Thermostat for Name, select Adventure Works for Account and select Save.

  4. Locate the Device ID field, enter smt-9876 and Save.

  5. Select Register Devices.

  6. Select OK.

  7. In your web browser, select a new tab and navigate to Azure portal (Log into Azure if prompted. You need an Azure subscription associated with the account you're using).

  8. Select Resource Groups and open your resource group.

  9. Open the IoT Hub that you're using with Connected Field Service, and select the Simulator

  10. Select the Simulator URL to open the Thermostat Simulator (The simulator should open in a new tab).

  11. On the simulator, select Connection.

  12. Switch back to your Azure subscription, close the simulator App Service screen.

  13. Open the IoT Hub.

  14. Highlight the IoT Hub name and Copy it.

  15. Switch back to your simulator screen and paste the IoT hub name into the Host field.

  16. Switch back to your Azure subscription, select Shared Access Policies.

  17. Open the iothubowner policy and copy the Primary key.

    Screenshot of the iothubowner policy with the Primary key copied.

  18. Switch back to your simulator screen and paste the Primary key into the Key field.

  19. Select the Connect button.

  20. Select the Refresh button to ensure all registered devices are available.

  21. From the Select a device drop down, select the smt-9876 device. (A green dot should appear next to the Refresh button, and after a few seconds it should start transmitting information.)

    Screenshot of the Select a device field with smt-9876 selected.

  22. On the Temperature Slider, set it to 75 Degrees and wait for the temperature status to register on in the Messages Sent window.

    Because the temperature was between 71 degrees and 85 degrees, a command is sent to the device to reboot it. (It can take several minutes for the reboot command to be sent to the device, depending on the internet speed.)

  23. Switch to the browser tab that has Connected Field Service loaded.

  24. Select IoT Alerts.

  25. Switch the view to Inactive IoT Alerts.

  26. Open the Temperature of 75 exceeded a threshold of 70 Alert.

  27. Select the Commands tab. (You should see a command that was sent to the device.)

    Screenshot of the Commands tab with a command sent to the device.

  28. Switch back to the web browser tab that contains your Simulator.

  29. Set the Temperature to 90 Degrees and wait for it to register in the Messages Sent window.

  30. Switch to the browser tab that has Connected Field Service loaded.

  31. Select IoT Alerts.

  32. Open the Temperature reading of 90 exceeded a threshold of 70 alert.

  33. Select the Created Stage. (Notice the information we extracted earlier is being displayed, and because the reading is between 86 and 100, create case it the next stage.)

    Screenshot of the Created stage with the Reading and Threshold highlighted.

  34. On the Menu select Send Command.

  35. Select Switch to Json.

  36. Enter the below code for the Command and select Send.

    {"CommandName":"Reset Thermostat","Parameters":{}}
    
  37. Switch back to your Simulator and wait for the device to Reboot.

  38. On the Temperature Slider, set it to 106 Degrees and wait for the temperature status to register on in the Messages Sent window.

  39. Switch to the browser tab that has Connected Field Service loaded.

  40. Select IoT Alerts.

  41. Open the temperature reading of 106 exceeded a threshold of 70 alert.

  42. Notice because the alert was above 100 degrees, that it skipped the Create Case stage completely.

    Screenshot of the Create Work Order stage with the Create Case stage skipped.