Permalink
Branch: master
Find file Copy path
497652a Sep 24, 2018
1 contributor

Users who have contributed to this file

270 lines (203 sloc) 16 KB

Set up for end-to-end demo

Configure O365

Create SharePoint site

  1. Go to your Office 365 organization's root SharePoint site.

  2. Choose Create Site, then choose Team site. Name the site Flight Admin and choose Next, then choose Finish.

  3. When the new site loads in the browser, locate the Documents web part. Using either the New or the Upload button in that web part, add a Word document called Flight Log.docx.

  4. On the site's home page, choose New in the upper-left corner, then choose List. Name the list Master Flight List and choose Create.

  5. When the new list loads in the browser, use the Add column button to add the following columns:

    Name Type Require a value? Other settings
    Flight Number Number Yes Number of decimal places: 0, Enforce unique values: Yes
    Admin Person Yes Allow selection of groups: No, Allow multiple selections: No
    Pilots Person Yes Allow selection of groups: No, Allow multiple selections: Yes
    Flight Attendants Person Yes Allow selection of groups: No, Allow multiple selections: Yes
    Catering Liaison Person Yes Allow selection of groups: No, Allow multiple selections: No
    Departure Gate Single line of text Yes
    Departure Time Date Yes Include time: Yes

When you're done, the list should look something like this.

Screenshot of the Master Flight List

Provision Azure Resources

Create a new Function App

  1. Go to the Azure Portal. Use the Create a resource button to add a new Function App.
  2. Once the app is created, navigate to it in the Azure Portal and select Platform Features.
  3. Choose Function app settings, then change the Runtime version to ~2 (Preview).
  4. Select Overview then select Get publish profile. Save the downloaded file, you'll need it later.
  5. Copy the URL value, you'll need it later.

Create app registrations

You need to create two app registration in the Azure Portal.

  1. Choose Azure Active Directory in the left-hand navigation in the Azure Portal.
  2. Under Manage, choose App registrations.

Register app for Azure Function

  1. Choose New application registration.
  2. Set the Name to Flight Team Provisioning Function.
  3. Set Application Type to Web app / API.
  4. Set Sign-on URL to the URL for the Azure Functions app, then choose Create.
  5. Copy the value of Application ID, you will need it later.
  6. Choose Settings, then choose Required permissions.
  7. Choose Add, then Select an API. Choose Microsoft Graph, then choose Select.
  8. Select the following under Delegated permissions:
    • Deliver and manage user notifications for this app
    • Invite guest users to the organization
    • Edit or delete items in all site collections
    • Read all users' full profiles
    • Read and write all groups
    • Have full access to all files user can access
    • Create, edit, and delete items and lists in all site collections
  9. Choose Select, then Done.
  10. In the Settings blade, choose Keys.
  11. Under Passwords, enter a description, select a duration, then choose Save. Copy the Value, you will need it later.

Register app for Microsoft Flow

  1. Choose New application registration.
  2. Set the Name to Flight Team Provisioning Connector.
  3. Set Application Type to Web app / API.
  4. Set Sign-on URL to https://localhost, then choose Create.
  5. Copy the value of Application ID, you will need it later.
  6. Choose Settings, then choose Required permissions.
  7. Choose Add, then Select an API. Type Flight Team Provisioning Function in the search box, then select Flight Team Provisioning Function in the list. Choose Select.
  8. Select the following under Delegated permissions:
    • Access Flight Team Provisioning Function
  9. Choose Select, then Done.
  10. In the Settings blade, choose Keys.
  11. Under Passwords, enter a description, select a duration, then choose Save. Copy the Value, you will need it later.

Update the app registration for the Azure Function

  1. Navigate to the Flight Team Provisioning Function app registration, then select Manifest.

  2. In the Edit manifest window, locate the line "knownClientApplications": [],, and replace it with the following (replacing app-id-for-flight-team-provisioning-connector with the application ID for your Flight Team Provisioning Connector app registration):

    "knownClientApplications": [
      "app-id-for-flight-team-provisioning-connector"
    ]
  3. Chose Save.

Create schema extension

This sample uses a schema extension to save the item ID of the SharePoint list item that initiated the team provisioning onto the group in Microsoft Graph. This is used to find the group later when archiving the team or notifying members of a change to the departure gate.

  1. Go to Graph Explorer and login with an administrator account.

  2. Change the method to POST, the version to beta, and set the URL to https://graph.microsoft.com/beta/schemaExtensions.

    A screenshot of the Graph Explorer request settings

  3. In the Request Body, add the following JSON, replacing app-id-for-flight-team-provisioning-function with the application ID for your Flight Team Provisioning Function app registration.

    {
        "id":"contosoFlightTeam",
        "owner": "app-id-for-flight-team-provisioning-function",
        "description": "Contoso Flight Team Provisioning extensions",
        "targetTypes": [
            "Group"
        ],
        "properties": [
            {
                "name": "sharePointItemId",
                "type": "Integer"
            }
        ]
    }
  4. Choose Run Query.

  5. In the Response Preview, locate the value of the id property. Copy this value.

  6. Open the ./create-flight-team/Graph/GraphResources.cs file and replace YOUR_SCHEMA_EXTENSION_NAME with the value you just copied.

Configure Microsoft Flow

Add custom connector for Azure functions

  1. Rename the postman_collection.json.example to postman_collection.json, then open it in a text editor.
  2. Replace all instances of https://<your-azure-function-url> with the URL to your Function App. Save your changes.
  3. Go to Microsoft Flow. Select the "gear" icon in the top right, then choose Custom Connectors.
  4. Choose Create custom connector, then choose Import a Postman collection.
  5. Enter Contoso Team Provisioning for Custom connector name, then browse for postman_collection.json in the Upload a postman collection (V1) field. Choose Continue.
  6. Under General information, verify that the Host field matches the URL of your Functions App, and the Base URL is set to /. Choose Security.
  7. Change Authentication type to OAuth 2.0, then fill in the fields as follows:
    1. Change Identity Provider to Azure Active Directory.
    2. Enter the application ID for the Flight Team Provisioning Connector app registration in the Client id field.
    3. Enter the application password for the Flight Team Provisioning Connector app registration in the Client secret field.
    4. Enter the application ID for the Flight Team Provisioning Function in the Resource URL field.
    5. Leave all other fields as their default values.
  8. Select Create connector. Copy the value of the Redirect URL, you will need it later.

Update app registration for Microsoft Flow

  1. In the Azure Portal, navigate to the Flight Team Provisioning Connector app registration.
  2. Select Settings, then Reply URLs.
  3. Add the value of Redirect URL you copied when creating the custom Flow connector to the list of reply URLs, and choose Save.
  4. Select Manifest

Create the "Create Team" flow

  1. Go to Microsoft Flow. Choose My flows.

  2. Choose Create from blank.

  3. On the next page, choose Create from blank.

  4. Enter SharePoint in the search box, then select SharePoint - When an item is created.

    1. Enter the URL to your Flight Admin site you created earlier for Site Address, then select Master Flight List for List Name.

    A screenshot of the When an item is created trigger

  5. Choose New Step, then Add an action.

  6. Enter variable in the search box, then select Variables - Initialize variable.

    1. Enter pilotEmails for Name, change Type to Array, leave Value blank.

    A screenshot of the Initialize variable action for pilotEmails

  7. Choose New Step, then More, then Add an apply to each.

    1. For Select an output from previous steps, under Dynamic content select Pilots.
    2. Choose Add an action
    3. Enter variable in the search box, then select Variables - Append to array variable.
      1. Enter pilotEmails for Name.
      2. For Value, under Dynamic content select Pilots Email.

    A screenshot of the Apply to each action for pilotEmails

  8. Choose New Step, then Add an action.

  9. Enter variable in the search box, then select Variables - Initialize variable.

    1. Enter flightAttendantEmails for Name, change Type to Array, leave Value blank.

    A screenshot of the Initialize variable action for flightAttendantEmails

  10. Choose New Step, then More, then Add an apply to each.

    1. For Select an output from previous steps, under Dynamic content select Flight Attendants.
    2. Choose Add an action
    3. Enter variable in the search box, then select Variables - Append to array variable.
      1. Enter flightAttendantEmails for Name.
      2. For Value, under Dynamic content select Flight Attendants Email.

    A screenshot of the Apply to each action for flightAttendantEmails

  11. Choose New Step, then Add an action.

  12. Enter Contoso in the search box, then select Contoso Team Provisioning - CreateFlightTeam.

  13. Choose Sign in. Be sure to use an administrator account when you sign in to create the connection. The permissions required by the sample require administrator consent.

  14. Once sign in and consent are complete, you should see a form for the action. Fill in the fields as follows using the Flow UI.

    1. sharePointItemId: Under Dynamic content choose See more, then select ID.
    2. flightNumber: Under Dynamic content choose See more, then select Flight Number.
    3. description: Under Dynamic content select Title.
    4. admin: Under Dynamic content select Admin Email.
    5. pilots: Choose the Switch to input entire array toggle to the right of the input box, then place your cursor in the input box. Under Dynamic content, select pilotEmails.
    6. flightAttendants: Choose the Switch to input entire array toggle to the right of the input box, then place your cursor in the input box. Under Dynamic content, select flightAttendantEmails.
    7. cateringLiaison: Under Dynamic content select Catering Liaison Email.
    8. departureGate: Under Dynamic content select Departure Gate.
    9. departureTime: Under Dynamic content select Departure Time.

    A screenshot of the CreateFlightTeam action

  15. Choose New Step, then Add an action.

  16. Enter notification in the search box, then select Notifications - Send me an email notification.

    1. For Subject, enter Microsoft Team created for Flight, then under Dynamic content choose See more, then select Flight Number.
    2. For Body, under Dynamic content select Link to item.

    A screenshot of the Send me an email notification action for success

  17. Hover over the arrow above the Send me an email notification action and choose the +, then Add a parallel branch, then Add an action.

  18. Enter notification in the search box, then select Notifications - Send me an email notification.

    1. For Subject, enter Error creating Microsoft Team for Flight, then under Dynamic content choose See more, then select Flight Number.
    2. For Body, enter Details:, then under Dynamic content select Body.
    3. Choose the ... on the action and choose Configure run after.
      1. Unselect is successful
      2. Select has failed
      3. Choose Done.

    A screenshot of the Send me an email notification action for failure

The email notification actions should look like the following when you're done.

A screenshot of the parallel email notification actions

Select Save to save the flow.

Create the "Archive Team" flow

  1. Go to Microsoft Flow. Choose My flows.

  2. Choose Create from blank.

  3. On the next page, choose Create from blank.

  4. Enter SharePoint in the search box, then select SharePoint - When an item is deleted.

    1. Enter the URL to your Flight Admin site you created earlier for Site Address, then select Master Flight List for List Name.

    A screenshot of the When an item is deleted trigger

  5. Choose New Step, then Add an action.

  6. Enter Contoso in the search box, then select Contoso Team Provisioning - ArchiveFlightTeam.

  7. Fill in the fields as follows using the Flow UI.

    1. sharePointItemId: Under Dynamic content choose See more, then select ID.

    A screenshot of the ArchiveFlightTeam action

Select Save to save the flow.

Create the "Notify Team" flow

For this flow, we will start with an existing template and modify it to our use. Unfortunately the Flow team removed the "When an existing item is modified" trigger for SharePoint from the UI when creating a blank flow. By using this template, we can get access to it.

  1. Go to the Microsoft Flow template. Choose Edit in advanced mode.

  2. In the When an existing item is modified box, enter the URL to your Flight Admin site you created earlier for Site Address, then select Master Flight List for List Name.

    A screenshot of the When an existing item is modified trigger

  3. Choose the ... on the Send Email box and choose Delete. Choose OK when prompted.

  4. Choose New Step, then Add an action.

  5. Enter Contoso in the search box, then select Contoso Team Provisioning - NotifyFlightTeam.

  6. Fill in the fields as follows using the Flow UI.

    1. sharePointItemId: Under Dynamic content choose See more, then select ID.
    2. newDepartureGate: Under Dynamic content select Departure Gate.

    A screenshot of the NotifyFlightTeam action

Select Save to save the flow.