With this post I will show you how you can quickly add classes for your JSON and XML in Power Platform using Visual Studio.
Sometimes, there will be requirements where you need to convert and replace your Power Automate Flows with custom code either usingPlugins or Actions. In this case, you may definitely need to parse the response returned by REST API calls and you might need to create relevant classes to hold the parameters and attributes, creating these manually would be cumbersome and takes few minutes of time even for a good developer.
Here I am taking the example using JSON.
So, without further due, let’s see in this in action.
Step 1: So, just copy using Cntrl + C shortcut, this is mandatory, else you will not able to see the Paste JSON as Classes and Paste XML as classes under edit..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In today’s no code world and AI, while most of the Apps are developed using low code approach, sometimes we have to go with the traditional way of development to handle any integrations with other systems.
When we give anyone Command Line script and ask them to execute, the other person would immediately open Search bar at the bottom available in Windows and start entering cmd. Immediately command prompt window appears and will be able to execute the same command.
But what if we ask to execute command line Commands from C# code…? So, in this blog post, I will show you how easily you can call command line commands with a simple example. Let’s get started…
Here in order to showcase, I will just use a basic command line command and run it from C#.
Everyone knows how to find the ipconfig command right, which just shows the internet protocol configuration when entered in command line like below.
In order to execute it from Console Application using C#, we would need to utilize the System. Diagnostics. You can utilize the below C# code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When we execute this command, it shows exactly same as what we saw above with Command Line.
In the same way we can call any Command Line Commands from C#. I have to use this approach for my Power Platform Implementation integration to decrypt encrypted messages using PGP and I found it to be very helpful and thought of sharing with all of you. If you were looking for a program to decrypt, you can check out for previous blog post here.
Every now and then when we were struck up with the issues with our code or with any power platform components like Power Automate, we had to definitely understand whether it is working from normal C# console application.
There were tons of articles over the internet and just it’s ophhhh…
So this post is just for a quick reference to connect to Dynamics 365 CE Instance to check if your actual function is returning valid data or not. I have just removed my functions for brevity.
You can just specify your Client Id, Client Secret, Instance URL below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;
using System.ServiceModel;
namespace TestConsole
{
internal class Program
{
static void Main(string[] args)
{
IOrganizationService orgService = GetOrganizationServiceClientSecret(your client id, your client secret, instance url);
var response = orgService.Execute(new WhoAmIRequest());//To validate the request
if(response != null)
{
Console.WriteLine("Connected to CRM");
//Your function here
}
}
public static IOrganizationService GetOrganizationServiceClientSecret(string clientId, string clientSecret, string organizationUri)
{
try
{
var conn = new CrmServiceClient($@"AuthType=ClientSecret;url={organizationUri};ClientId={clientId};ClientSecret={clientSecret}");
return conn.OrganizationWebProxyClient != null ? conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
}
catch (Exception ex)
{
Console.WriteLine("Error while connecting to CRM " + ex.Message);
Console.ReadKey();
return null;
}
}
}
}
Whenever you want to check any thing from C# Console, I hope this piece code works for connecting to your Dynamics.