Execute Dynamics 365 Action from an external application using C#

The following blog explains how to connect to a Dynamics 365 instance from an external application (ex. ASP.NET web application), how to execute a global action providing the input arguments and retrieve the output argument once it runs.

First thing’s first – add a reference to the Microsoft.CrmSdk.CoreAssemblies package to your project.

In Visual Studio click on Tools on the top menu, then click NuGet Package Manager, and then Manage NuGet Packages for Solution.
Then go to Browse and search for Microsoft.CrmSdk.CoreAssemblies.
Select the Project you are working on and install a version that is compatible with your Dynamics 365 version.

The following code makes a connection to your Dynamics 365 Organization:

You can get the organization URL from Dynamics 365.
Navigate to Settings -> Customizations -> Developer Resources. Copy and Paste Organization Service Endpoint Address URL.

For the purpose of this tutorial we created a simple global action that creates a new Lead in Dynamics.
The action has three input arguments (TopicFirstNameLastName) and one output argument (NewLeadURL).

The action creates a new Lead with the values from the three input arguments and sets the newly created Lead’s URL as an output parameter to be used in your application.

The following C# code executes the action with the three arguments using the organization service we initialized previously.

If you want to use the output argument in your code, you can get it from the response like bellow:

A new Lead was created in Dynamics with the specified values:

We use cookies for better experience.