Views:

Overview

This is the second part of a two part series. Please see here if you have not completed the setup guide yet. 

Now that the Active Directory Security has been set up on Azure functions, this article will show how to execute Azure functions via North52. 

First, we will setup the xCache records where we will store our unique parameters and secrets. 

Second, we will create the formula that uses these xCache records and calls the Azure function from the setup article. 

Third, we will then test this formula. 

Create xCache records

  • Go to Settings > N52 Formula
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_DirectoryID
    • Scroll down and in Value (Secured), enter your Directory ID
      • In this example, we will paste the Directory ID we copied from the setup article
  • Click Save
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_Resource
    • Scroll down and in Value (Secured), enter your Resource 
      • In this example, we will paste the Resource we copied from the setup article
    • Click Save
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_ClientID
    • Scroll down and in Value (Secured), enter your Client ID
      • In this example, we will paste the Client ID we copied from the setup article
    • Click Save
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_ClientSecret
    • Scroll down and in Value (Secured), enter your Client Secret
      • In this example, we will paste the Client Secret we copied from the setup article
    • Change the DataType to String (Password)
    • Click Save
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_FunctionURL
    • Scroll down and in Value (Secured), enter your Function URL
      • In this example, we will paste the Function URL we copied from the setup article
    • Click Save

Create N52 Formula

  • Go to Settings > N52 Formula
  • Click New
  • Set Formula type to Clientside - Calculation
  • Select Editor to be Classic
  • Leave Entity as Account
  • Click Create
  • Give it the name Azure Functions with Active Directory Security 
  • Copy and paste the formula below:
    Smartflow(
      SetVar('token',
        azureadgettoken(xCacheGetGlobal('AzureFunctions_DirectoryID'), 
          SetRequestParams(
            'resource', xCacheGetGlobal('AzureFunctions_Resource'), 
            'client_id', xCacheGetGlobal('AzureFunctions_ClientID'),
            'client_secret', xCacheGetGlobal('AzureFunctions_ClientSecret'),
            'grant_type', 'client_credentials'))),
    
      CallRestAPI( 
        SetRequestBaseURL(xCacheGetGlobal('AzureFunctions_FunctionURL')),
        SetRequestResource(''),
        SetRequestDetails('GET'),
        SetRequestHeaders('Authorization', 'Bearer ' + GetVar('token'), 'Content-Type', 'application/json; charset=utf-8', 'Accept', 'application/json'),
        SetRequestParams('name', 'Bill Gates'),
        SetRequestAuthenticationNone(),
        SetRequestFiles(), 
        SetRequestExpected('OK'),  
        SetRequestActionPass(getvar('responsecontent')),
        SetRequestActionFail(getvar('responsecontent'))))
    
  • Click Save

Test

  • Click on the lightning bolt button in the top right of the formula editor
  • Click Execute
  • You will see the result appear:

Did you know?

TestShield Makes Test Automation a First Class Citizen in Dynamics 365

Test automation principles leads to improved communication, reliability and teamwork as you enhance the ever changing business processes. The team members need to roll out change requests on the existing system and build new applications making automated testing very important. 

Top 3 Benefits of Dynamics 365 Automated Testing:
  • Validated Business Processes: Dynamics 365 Automated Testing provides a robust approach to validate the business rules and process requirements of Dynamics 365 solutions
  • Better Engagement: Dynamics 365 Automated Testing ensures that end users get top-class user experience
  • Faster Delivery Time: Dynamics 365 Automated Testing assures fast delivery time by leveraging automation

The growing number of Dynamics applications that are being developed continuously presents a major challenge for Dynamics 365 testing. With such fast development, organizations need to ensure that these applications are thoroughly and constantly tested before being deployed.

Learn how TestShield helps automate testing in your Dynamics 365 projects