This is a continuation of my series on a proof of concept to allow Alexa to interact with D365 Field Service
- The Business scenario (Part 1)
- Create an Alexa Skill (Part 1)
- Connect the Skill to D365 (Part 2)
- Use Field Service to book an appointment (This Part)
- Return the information to Alexa (Part 2)
In this final (unless I need to expand on the scenarios) part of the story, Flow will be used to take the information garnered from the user and create a work order.
Calling a Sub-flow
The original flow was all about Alexa, but what about other voice assistants? Flow is no different that any other programming languages and as such we can use the same concepts to writing decent flows, one of them being re-usability. If the code to write the Work order and book it is generic, it can be re-used when Google or Siri is connected to the application.
To this end, the Flow starts with another HTTP trigger, which is called from the previous flow.
Just like when connection Flow to Alexa, the URL is required in the child to update the caller. Create a new Flow, using the When a HTTP request is received. As content to the JSON Schema, add just enough to get you going and use the output to send an email so that the schema coming from the parent flow can be seen. This is a repart of the logic used to start our parent flow.
Once saved, the URL will be generated in the trigger step. Use this to call the child Flow from the parent. This is the HTTP action. The Method is a POST, the URI is the trigger URL defined in the child Flow. No headers are required. In the body, add in the things that are already known, just to ensure repeat calls to D365 are made. The Intent is also passed in, which has all the details about what the user wanted.
Now ready for testing, ensure both Flows are in Test mode and trigger Alexa. After a little delay, an email should be sent in the child Flow detailing enough information to create a Work Item.
Use this email to populate the JSON as previously, easily creating the schema that is required.
Creating a Work Order
Next, get the Account the contact is associated with. This is done with a call to the D365 Instance using the Common Data Service Connector.
A Work Order needs some fields to be set before it can be save, Work Order Type is one of them. This could be hard coded, but Alexa has supplied the intent. To match the Work order type with the intention in Alexa, a field on the Work Order Type was added, Alexa Intent, which is searched for in the CDS List Records action.
To make the Flow easier to manage and reduce the dual looping, the Work Order Type is returned to a variable
Once the data for the new Work Order is available, create the Work Order using the CDS Create Record connector.
Most of these are obvious, but the one that is not is the Work Order Number. In Field Service, this is automated, with a prefix and a number range. As this doesn’t work in Flow, a work number is generated using a random number, using an expression.
A few other parts of the work order are populated, helping the service manager to match the time as appropriate.