Saturday, March 26, 2022

How to create record in dcrm using azure function

 Step 1. Go to https://portal.azure.com/

 Step 2. Create the App Registration. Just provide Name and click on Register. 




Step 3.  Once you create the App Registration then click on the certificate and secrets and click on the new and provide the description and expire date pleases see the screenshot.



Now just copy the client secret value because after 10 minutes you will not able to see the entire value please make sure you copy your client value.

Step 4. Now give the API Permission in App Registration click on the add permission and select the dynamic CRM then choose the delegate one and check the user_immersion then click on add permission please see the below screenshot.


If you are thinking why we are creating App Registration please flow the below link 
 

Step 5. Now create the Application User. Go to power platform admin center and create the application user please follow the step you will be able to Create it.

                                                                                           

Now you set up the application user. Now you can create the code in visual studio and do the operations like create, update, delete etc. in DCRM.                                                                                                    

Step 6. Now open the visual studio create new project search the Azure Function and select the               
Right click on the project and install the nuget package a. Microsoft.PowerPlatform.Dataverse.Client b. Crmsdk.coreAssembly. install the both the package and provide the Directories.                                     
Step 7.Now copy paste the code in visual studio.                                                                                       
                                                                                            
  • using System;
  • using Microsoft.Azure.WebJobs;
  • using Microsoft.Azure.WebJobs.Host;
  • using Microsoft.Extensions.Logging;
  • using Microsoft.PowerPlatform.Dataverse.Client;
  • using Microsoft.Xrm.Sdk;

  • namespace Timer_Trigger
  • {
  •     public static class Function1
  •     {
  •         [FunctionName("Function1")]
  •         public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
  •         {
  •             log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
  •             Connect();
  •             Entity e = new Entity();
  •         }
  •         public static void Connect()
  •         {
  •             //  log.LogInformation("C# HTTP trigger function processed a request.");
  •             ServiceClient crmServiceClient = null;
  •             System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
  •             var clientId = "8182544c-3485-4bc3-9884-81617d48e39a";
  •             var clientSecret = "8jm7Q~nhPHGP0Ccl-6a5ow2Tivf4LzADLdZMR";
  •             var organizationUrl = "https://org13ffb2c4.crm8.dynamics.com/";
  •             string connectionString = "Url=" + organizationUrl + "; " +
  •             "AuthType=ClientSecret; " +
  •             "ClientId= " + clientId + "; " +
  •             "ClientSecret=" + clientSecret;

  •             crmServiceClient = new ServiceClient(connectionString);
  •             if (crmServiceClient.IsReady)
  •             {

  •                 CreateRecord(crmServiceClient);

  •             }
  •         }
  •         private static void CreateRecord(ServiceClient crmServiceClient)
  •         {
  •             try
  •             {
  •                 Entity newAccount = new Entity("account");
  •                 newAccount["name"] = "Account is crated through Azure";
  •                 crmServiceClient.Create(newAccount);

  •                 //Write the program here


  •             }
  •             catch (Exception)
  •             {

  •                 throw;
  •             }
  •         }
  •     }
  • }
 put the debugger on the Gary side of visual studio 






                                    







No comments:

Post a Comment

How to create record in dcrm using azure function

 Step 1. Go to  https://portal.azure.com/  Step 2. Create the App Registration. Just provide Name and click on Register.  Step 3.  Once you ...