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.
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.
- 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;
- }
- }
- }
- }