Giter Club home page Giter Club logo

connecting-to-dynamics-cds-sdk's Introduction

Connecting To Dynamics With the CDS SDK

The repository contains a v3 .NET Azure Function that uses the CDS SDK to execute actions against Dynamics entities. The function app contains a single service bus queue triggered function that uses the message contents to create a new Account entity in a Dynamics environment, then perform read, update, and delete operations on the entity.

The README is designed to walk the user through configuration of a Dynamics environment and execution of the sample function.

Pre-Requisites

Set Up Client Secret Authentication

In order to connect to Dynamics via the CDS SDK, client secret authentication must be utilized. The flow essentially requires that a service principal be granted access to the Dynamics environment. An Azure Active Directory application must be created in the tenant that contains the pre-provisioned Dynamics environment, and that application must be added to the Dynamics environment as an 'Application User' by a Dynamics system administrator.

Create an Azure Active Directory App

  • Navigate to the Azure Portal and sign in with an account within the directory that contains the Dynamics environment.

  • Search for 'Azure Active Directory' and select it.

  • Select the 'App registrations' blade, then click '+ Add Registration'.

  • Give the app a name. Under 'Supported account types' select 'Accounts in this organizational directory only' and ensure the 'Redirect Uri' is set to type 'Public Client/native (mobile & desktop)'.

  • Register the app.

Create an Application User

Note: The following steps must be executed by a user with the 'System Administrator' role in Dynamics

  • Navigate to the Power Platform Admin Center.

  • Find the 'Environments' blade and select the proper environment. Open the 'Environment URL'.

  • Click the Settings icon and select 'Advanced Settings' from the dropdown, which loads the environment settings page.

  • Find the Settings dropdown and select 'Security' under 'System'.

  • Select the 'Users' link.

  • Switch the view to 'Application Users' (default is 'Enabled Users'), then click '+ New'.

  • Input the Application ID and Object ID from the Azure AD app in the 'Application ID' and 'Azure AD Object ID' fields in the form, respectively. Fill in the other fields with any value and click 'Save'.

Run the Azure Function

The function app uses the v0.2.14-Alpha prerelease version of the Microsoft.PowerPlatform.Cds.Client package for interaction witt the CDS and Dynamics, Microsoft.Azure.Functions.Extensions for Azure Functions dependency injection, and Newtonsoft.Json for basic JSON deserialization.

The function app's single function, Function1, is designed to connect to Dynamics using the the CdsServiceClient class provided by the SDK. The function then uses the service client to execute WhoAmI and CRUD operations against the environment. The function gains access to a singleton CdsServiceClient through dependency injection so as to not recreate the service client on each invocation.

Restore the Project Dependencies

Open the project in a cmd window and run dotnet restore.

Create the local.settings.json file

The sample.local.settings.json file serves as an example for the local.settings.json file that defines the environment variables for the function. Rename the file to local.settings.json and fill in the empty fields.

  • DynamicsEnvironmentUrl is the url that was opened via the Power Platform Admin Center (e.g. https://orga000c00a.crm.dynamics.com).

  • DynamicsClientId and DynamicsClientSecret can be found on the Active Directory app registration on the Azure Portal.

  • ServiceBusConnectionString can be found in the 'Shared access policies' blade of the Service Bus namespace in the Azure portal.

Update the Trigger Attributes

The sample function expects the queue to be named myqueue by default. Open the Function1.cs file and update the name of the queue to trigger off of.

Run the Function

The function can be run directly from Visual Studio or VS Code. Alternatively, open the project in a cmd window and run func host start.

Send Messages To The Service Bus Queue

  • Open the Service Bus Explorer

  • Click File -> Connect and input the Service Bus connection string

  • When the namespace has been loaded, right click the queue and click 'Send Messages'

  • Send a message with 'Message Text' conforming to the following structure:

{"AccountName":"SampleAccount","ZipCode":"48103","Revenue":100}

connecting-to-dynamics-cds-sdk's People

Contributors

lucashuet93 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.