cancel
Showing results for 
Search instead for 
Did you mean: 

Part 3 - Build a referral tracking system with Microsoft Flow, Azure Functions and your own CRM

Test your ConnectWiseGetContactByID Function

 

  1. Return to your ConnectWiseGetContactByID function
    In the Request Body window on the right, copy and paste the following JSON and click Save and Run.
    {
        "item": "25"
    }
  2. Keep an eye on the Output window, you should see the details for a ConnectWise contact appear in JSON format.
    If this particular contact ID doesn't return a result, do a bit of trial and error with Contact IDs to retrieve a contact that does. Ideally, you want to retrieve the details for a customer's contact record. The ConnectWise member contacts can include some extra JSON schema that doesn't apply to customers.
  3. Copy the JSON content from the Output window and save it somewhere. We'll be using this as sample schema in a later step.CopyFunctionOutput.png
  4. Copy the Azure Function Authorization URLs from both the ConnectWiseGetContactByID and ConnectWiseAddOpportunity Azure Functions. You can retrieve this by clicking Get function URL, then copying the result.ClickGetFunctionURL.png
  5. Save these somewhere for later. We'll use these to call Azure Functions from Microsoft Flow.RetrieveAzureFunctionURL.png

Complete your Microsoft Flow

 

  1. Return to your Microsoft Flow and remove the action below the Request trigger
  2. Add an Apply to each step and add the entries output from the popout menu to the ‘Select an output’ field. Then add a SharePoint – Get Items action into the Apply to each step and select or enter your SharePoint site, then choose the SharePoint list you created earlier.ApplyToEach.png
  3. Click Show advanced options and add gfid eq ‘id’ into the Filter Query field. Where ‘id’ is the id output from the Request trigger. Be sure to include the single quotes. This step checks the SharePoint List for existing entries with the same Gravity Forms entry ID.FilterByGFID.png
  4. Next add a Condition step, and click Edit in advanced mode. Copy and paste the following into this field:
    @empty(body('Get_items')?['value'])
    This checks whether any items were returned from SharePoint that match that Gravity Forms ID. If there weren’t any, we’ll create one.AddAConditionStep.png
  5. Your flow layout should now look like this:

     

     

     

    FlowShouldLookLikeThis.png

     

  6. In the Yes outcome, add in a HTTP - HTTP action, this will call the ConnectWiseGetContactByID function.
  7. Choose POST for the method and paste in the Authorization URL for the ConnectWiseGetContactByID function into the Uri field.
  8. In the Body field you can enter the following code: 
    {"item":"@{items('Apply_to_each')?['1']}"}}}
    This will work providing that the contact's ID was in the Gravity Forms field with an ID of 1. If it's not, you'll need to update the 1 to the field ID that contains the contact ID. Alternative, you can compose your Request body as per this screenshot. Keep in mind that the current Flow interface can get unweildy when dealing with a lot of outputs in a request body, so you may decide to type the longer bodies using the Workflow Definition Language schema.AddHTTPStep.png
  9. When run, this step is going to return the JSON output that we copied when testing the ConnectWiseGetContactByID function. To use this returned data, we'll need to parse the JSON into its values. Add a Data Operations - Parse JSON Action. In the Content field, drag in the output from the HTTP - HTTP step, then click Use sample payload to generate schema. Paste in the output that we saved from the ConnectWiseGetContactByID Azure Function and click Done.ParseJSON.png

  10. Now we want to create an item in SharePoint with the referral details, and the details of the contact that provided it. Add a SharePoint - Create Item step and select your site and referrals list. Populate the fields with the corresponding field IDs from your Gravity Form. Use the outputs from the Data Operations - Parse JSON step to add in the referring contact's info.CreateItemInSharePoint.png

  11. Add an Office 365 - Send Email step with the referral info to notify yourself that a new lead has arrivedSendEmail.png

  12. Add another HTTP - HTTP step. You can rename this one to HTTP - Add Opportunity.

  13. Set the Method to POST and paste the ConnectWiseAddOpportunity Authorization Url into the Uri field.

  14. For the request body, I recommend you copy and paste this JSON output into the Body field as it can be quite difficult to format a call using this number of outputs. You may need to tweak this JSON to match the specific IDs for your Gravity forms field ID values. 

    {
        "companyId": "@body('Parse_JSON')?['company']?['id']",
        "contactId": "@body('Parse_JSON')?['id']",
        "siteId": "@body('Parse_JSON')?['site']?['id']",
        "opportunityName": "Referral to @{items('Apply_to_each')?['3']} from @{body('Parse_JSON')?['firstName']} @{body('Parse_JSON')?['lastName']}",
        "notes": "Contact Person: @{items('Apply_to_each')?['4']} \r\nPhone: @{items('Apply_to_each')?['6']} \r\nExtra Info: @{items('Apply_to_each')?['7']}"
    }

    It should look like this once you update the Flow:AddOpportunityStep.png

Test your flow by running your Visual Studio Function App

 

  1. Return to Visual Studio and press F5 to resend your referral form entry to Microsoft Flow
  2. You should now see a new entry for the referral in your SharePoint listReferralInSharePoint.png
  3. You should receive an email notificationNewEmailNotification.png
  4. You should also now see a new opportunity in ConnectWiseNewOpportunity.png

     

Publish your local Azure Function App

 

To make sure that your form data stays up to date, we need to publish our Function App to Azure.

 

  1. Switch to Visual Studio, and update the timer on your function app to ‘0 0 */4 * * *‘ to make sure it doesn’t keep running each minute in the cloud.
  2. Now, right click on your project name and click PublishPublishFunctionApp.png
  3. Click Azure Function App, and choose Create New.PublishToNewAzureFunctionApp-1030x674.png
  4. Since we’re creating a new Azure Function App we need to specify some details. As mentioned earlier, Function Apps are just Azure Web Apps. To deploy them, we need to create or choose an App Service. Give your Function App an App Name, select your Azure subscription, choose or create a Resource Group, App Service Plan and Storage Account. You can use the same App Service Plan that you used for the other Function App. Alternatively, you can just choose the Consumption Plan.SetFunctionAppSettings.png
  5. Once you’re happy with your settings, click OK, then Create, and wait for your App Service to deploy.WaitForFunctionAppToDeploy.png
  6. When it finishes, click Publish. Your function app is now deploying to Azure.ClickPublishToPublishFunctionToAzure.png
  7. Sign in to https://portal.azure.com to see it in action under Web Apps. By default, your functions are in Read Only mode, and you won’t be able to view or edit the underlying C# code. I Have an extra function here because I'm also importing website enquiries.FunctionApps.png
  8. To keep track of your function’s activity, you can see function runs in the Monitor Section.CheckFunctionAppRuns.png

 

Elliot Munro is an Office 365 MCSA and Partner at GCITS - See the GCITS knowledge base for scripts and articles on administering Office 365 for managed service providers.

 

Meet Our Blog Authors
  • Co-founder of https://plumsail.com, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • Solution Architect with Slalom, and organizer of the Boston Office 365 User Group, and long term SharePoint/Office 365 veteren. Find more at http://www.davidlozzi.com. Follow @DavidLozzi
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc ( https://triad.co.uk)
>