Views:

Overview

Note: A simpler implementation of this functionality can be achieved without creating an Azure Web Application, see the alternative method in this article.

This article shows how you can execute a North52 Decision Table as part of a Flow and return a value back to the Flow to be used in a later step. This is conceptually very similar to how the Process Genie functionality works for standard Dynamics 365 workflows.

The business scenario is that we need to create a Dynamics 365 Task record with a due date at the end of the month. At the time of writing there is no easy way to do this with regular Flow functionality but it can be easily achieved with a North52 function. 

This concept can be extended for use in much more complex scenarios than the example shown below.

North52 Decision Suite

The North52 Decision Suite solution works like this:

  • A Custom Action is set up with a single Output parameter
  • A Formula is set up on the Custom Action which returns the last day of the month using the GetLastDayOfMonth function
  • A Microsoft Flow is set up to:
    • Call the Custom Action via the Web API and retrieve the last day of the month value
    • Create an new Task record with Due Date set to the value returned from the Custom Action

Set up Azure Web App, Global Action, Formula and Flow

This example requires a number of components to be set up; an Azure Web Application, a Global Action, a North52 Formula and a Microsoft Flow.

Azure Web App

To call the Global Action within your Flow we need to use an Azure Web App which has permission to call the Dynamics 365 web api. If you don't have one already set up follow these instructions:
  • Sign in to the Azure portal
  • If your account gives you access to more than one, click your account in the top right corner, and set your portal session to the desired Azure AD tenant
  • In the left-hand navigation pane, click the Azure Active Directory service, click App registrations, and click New application registration
  • When the Create page appears, enter your application's registration information:
    • Name: Enter a meaningful application name
    • Application type: select Web app / API 
    • Sign-On URL: use http://localhost 
  • Click Create. Azure AD assigns a unique Application ID to your application - note this down as we need it later when creating the Flow
  • Select Settings in the app info page
  • On the Settings page, select Required permissions > Add to add permissions for the registered app
    • On the Add API access page:
      • Select Select an API > Dynamics 365 Online, and then click Select
      • Select Select permissions > Access CRM Online as organization users, and then click Select
      • Select Done to add the delegated permission to the registered app
    • From the Required Permissions page select Grant Permissions
  • On the Settings page, select Keys 
    • On the Keys page, under the Passwords section:
      • Enter Flow (you can use another name if you like) for the Description
      • Select the Duration for when the key should Expire
      • Select Save - note down the key before moving away from this page 
  • Finally, we need to set up the Application user in Dynamics 365
    • In Dynamics 365 navigate to Settings > System > Security > Users
    • Change the view to Application Users
    • Click the New button
    • Enter the Application ID from above in the Application ID field
    • Click Save
    • Select Manage Roles
      • Assign a custom security role (it cannot be an out of the box role) which has the permissions required perform the necessary actions in the Formula - in this case the North52 Formula Manager - Standard security role will be sufficient
      • Click OK

Global Action

We need to set up a Global Action process which will then use a North52 formula to return a value in the output parameter.
  • Navigate to Settings > Processes
  • Click New to create a new Process:
    • Enter Last Day of Month for the Name
    • Select Action from the Category list
    • Select None (global) from the Entity list
    • Click OK
  • On the Process form window which opens:
    • Click the + (Add) button in the Process Arguments section
    • Type Output for the Name replacing the default NewArgument text
    • Select DateTime from the Type list
    • Select Output for the Direction
  • Click Save
  • Click Activate

Formula

For this simple example there are no Conditions and a single Action. However, this same method can be used to call Actions with complex business rules.

  • Create a new Formula, setting the following values in the Formula Guide:
    • Source Entity set to N52 Command
    • Set Formula Type to Action
    • Select the Decision Table editor
  • Change the Name of the formula to Action - Last Day of Month
  • Set the Action Event to new_LastDayofMonth (your Action from the Global Action section above)
  • Click Save
  • Right-click on the Decision Table sheet, select Set Sheet Options and check Use Action
  • Select column A, right-click and select Delete > Delete Column to remove the Condition column
  • Select cell A2
    • Go to the Source tab and expand Processes > Actions > none > new_LastDayofMonth and select Out: Output ( DateTimeOffset- false ) 
    • Note that the "none" node is for Global Actions (i.e. is no Entity associated)
  • Select cell A4
    • Select the Functions tab, type getlast into the Search Functions input box and press enter
    • Shift-click on the GetLastDayOfMonth function to open the function wizard:
      • Leave the Friendly Name blank as we will insert the function directly into the cell
      • Put the cursor into the Input Date field, then replace the previous function search by typing utc into the Search Functions input box and press enter
      • Select the UtcDate() function to add it to the Input Date field
      • Leave Offset blank
      • Click Generate
  • Click Save

Flow

  • Go to https://flow.microsoft.com/manage/flows/
  • Select Create from Blank
  • In the top left of the screen rename your flow to Create Task with End of Month Due Date
  • Enter manually trigger in the Search all connectors and triggers input box
    • Select the Flow button for mobile - Manually trigger a flow trigger
  • Select + New Step > Add an action
    • Enter http in the Search all connectors and actions input box
    • Select the HTTP- HTTP action, configuring it as follows:
      • Select the ... menu option Rename
        •  Enter HTTP - Call Dynamics 365 Action - North52 Decision Table
      • Method: select Post
      • URI: enter the Instance Web API Service Root URL from Settings > Customizations > Developer Resources, followed by the schema name of your Action:
        • e.g. https://tenant.crm.dynamics.com/api/data/v8.2/new_LastDayofMonth
      • Headers: add the following key/values:
        • OData-MaxVersion 4.0
          OData-Version 4.0
          Accept application/json
          Content-Type application/json; charset=utf-8
      • Queries: leave blank
      • Body: leave blank
      • Select Show advanced options
      • Cookie: leave blank
      • Authentication: select Active Directory OAuth
      • Authority: enter https://login.windows.net
      • Tenant: Your Azure Active Directory tenant ID
        • Go to https://portal.azure.com, select Azure Active Directory from the Services, then select Properties from the Overview page
        • Copy the Directory ID from the Properties page
      • Audience: your main Dynamics 365 url e.g. https://tenant.crm.dynamics.com/
      • Client ID: the Azure Web Application ID you created and noted down above
      • Credential Type: select Secret
      • Secret: the Key you created and noted down above
  • Select + New Step > Add an action
    • Enter parse in the Search all connectors and actions input box
    • Select the Data Operations - Parse JSON action
      • Content: select Body from the Dynamic Content
      • Schema: enter the follow JSON schema:
        {
        "type": "object",
             "properties": {
                  "Output": {
                       "type": "string"
                  }
             }
        }
  • Select + New Step > Add an action
    • Enter dynamics in the Search all connectors and actions input box
    • Select Dynamics 365 - Create a new record
    • Select the ... menu option Rename
      • Enter Create a new Task record with Due Date end of month
    • Organization Name: select you Dynamics 365 organization you wish to create your record in (you may need to add a new connection first)
    • Entity Name: select Tasks
    • Subject: enter New Task from Flow: Due followed by a space and then select Output (under Parse JSON section) from the Dynamic content options
    • Select Show advanced options
    • Due Date: select Output (under Parse JSON section) from the Dynamic content options. You may need to select the See more option
  • Save your Flow

Testing

While in the Flow editor click the Test button from the top right of the screen and follow the instructions. Ensure that there are no errors and verify that the Task has been created in Dynamics 365.

Did you know?

xCache can help with advanced Case prioritization rules

Every organization has different rules for managing case prioritization, some can be very complex.  With North52's business rules engine for Microsoft Dynamics 365 you can use the xCache functionality for impelementing highly efficient case prioritization rules. 

Learn how we do it in this knowledge base article