<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Imran</title>
    <description>The latest articles on DEV Community by Imran (@imrancodebug).</description>
    <link>https://dev.to/imrancodebug</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F583578%2F3b93cfe3-4bfc-4617-b059-59911fa3b962.jpeg</url>
      <title>DEV Community: Imran</title>
      <link>https://dev.to/imrancodebug</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imrancodebug"/>
    <language>en</language>
    <item>
      <title>Connecting to Dataverse using AuthCode flow and CrmServiceClient</title>
      <dc:creator>Imran</dc:creator>
      <pubDate>Wed, 21 Jul 2021 13:53:31 +0000</pubDate>
      <link>https://dev.to/imrancodebug/connecting-to-dataverse-using-authcode-flow-and-crmserviceclient-jnp</link>
      <guid>https://dev.to/imrancodebug/connecting-to-dataverse-using-authcode-flow-and-crmserviceclient-jnp</guid>
      <description>&lt;p&gt;Here a quick example of connecting to Dynamics using &lt;code&gt;CrmServiceClient&lt;/code&gt; in Microsoft.CrmSdk.XrmTooling.CoreAssembly &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


</description>
      <category>dynamics365</category>
      <category>dataverse</category>
      <category>crmserviceclient</category>
    </item>
    <item>
      <title>Difference Between Function and Action in Dynamics World</title>
      <dc:creator>Imran</dc:creator>
      <pubDate>Fri, 07 May 2021 06:45:47 +0000</pubDate>
      <link>https://dev.to/imrancodebug/difference-between-function-and-action-in-dynamics-world-obp</link>
      <guid>https://dev.to/imrancodebug/difference-between-function-and-action-in-dynamics-world-obp</guid>
      <description>&lt;p&gt;I always forget which ones which and this does matter when we are coding against Xrm.WebAPI (JS). Also, it is a terrific interview question. &lt;/p&gt;

&lt;h2&gt;
  
  
  Function
&lt;/h2&gt;

&lt;p&gt;Functions are reusable blocks of code that do not have any side effects. Meaning after the execution of a function no record will be updated. &lt;code&gt;WhoAmI&lt;/code&gt; is an example of a function. You would call the function with a &lt;code&gt;GET&lt;/code&gt; and this is a very important feature of a function. Also to my understanding, you cannot create a custom function. Meaning all the functions are defined by MS. The list of all the functions are to be found &lt;a href="https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/functions?view=dynamics-ce-odata-9"&gt;here&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Action
&lt;/h2&gt;

&lt;p&gt;Actions are blocks of reusable code that can or cannot have any side effects. (confusing much??). You can create custom actions and all the actions are called with a &lt;code&gt;POST&lt;/code&gt;. An action can be bound to an entity and it is then called a &lt;em&gt;bound action&lt;/em&gt;. An action can also be global and does not depend on any table and naturally, these are called &lt;em&gt;unbound action&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Both actions and functions are considered to be full-scale SDK message. Meaning you can register a plugin at various stages of action.  &lt;/p&gt;

&lt;p&gt;More details can be found here, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/powerapps/developer/data-platform/webapi/use-web-api-functions"&gt;Functions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/powerapps/developer/data-platform/webapi/use-web-api-actions#unbound-actions"&gt;Actions&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dynamics365</category>
      <category>dataverse</category>
    </item>
    <item>
      <title>Connecting to Dataverse using MSAL Authcode flow</title>
      <dc:creator>Imran</dc:creator>
      <pubDate>Sun, 28 Mar 2021 15:11:25 +0000</pubDate>
      <link>https://dev.to/imrancodebug/connecting-to-dataverse-using-msal-authcode-flow-1h1</link>
      <guid>https://dev.to/imrancodebug/connecting-to-dataverse-using-msal-authcode-flow-1h1</guid>
      <description>&lt;p&gt;Here’s a quick example of connecting to Dataverse with MSAL using auth code flow. I have performed the following step,&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Creation of Application Registration
&lt;/h1&gt;

&lt;p&gt;As the name suggests Application Registration registers your application to talk to Dataverse. The details of how to register an application in azure can be found in &lt;a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app"&gt;Microsoft docs&lt;/a&gt;. However, I am listing the steps I have taken below,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In &lt;a href="https://portal.azure.com"&gt;Azure Portal&lt;/a&gt; select Azure Active Directory and I have selected App Registrations. Then clicked on New Registrations.&lt;/li&gt;
&lt;li&gt;On the new pane I have set the name of my application. On the Redirect URI select Public Client/Native as I am building a class library. I have left everything else as default.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1sMpOALY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w77q3m6xtkq7d4fztnzd.png" alt="image"&gt;
&lt;/li&gt;
&lt;li&gt;After the application registration is created, click on the Api Permissions from the left-hand side. In the new blade under Configured Permission section click on Add Permission. In the new blade select Dynamics CRM option. 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---YJWwGwv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6c5iphp0kl545ye76p0.png" alt="image"&gt;
&lt;/li&gt;
&lt;li&gt;There should be only user_impersonation option there. Select that option and press Ok. The name and placement of Dynamics CRM option has changed a few times. If you do not see the option, it is more likely that they have changed the name, placement, or both. 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---kZK_Gkg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vpz8zy56di16w5m6c0fj.png" alt="image"&gt;
&lt;/li&gt;
&lt;li&gt;Your Configured Permissions should look like below,
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EmQfkHBU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wtgsae20yumlhayfi5uy.png" alt="image"&gt;
&lt;/li&gt;
&lt;li&gt;Click on Certificates and Secrets node on the left and in the new blade click on new Client Secret button. On the pop window create a meaningful name and set the expiry and then select Add. In the next window make a note of the client secret.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MaDVLL6A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcm5lhql29ayvy4x05do.png" alt="image"&gt;
&lt;/li&gt;
&lt;li&gt;Make a note of the following from the Overview section in the,

&lt;ul&gt;
&lt;li&gt;Client Id&lt;/li&gt;
&lt;li&gt;Tenant Id&lt;/li&gt;
&lt;li&gt;App secret that has been generated in the step 6.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j2gtxq7r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4j5akug05fst16mlks3q.png" alt="image"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  2. Create an application user in Dynamics 365
&lt;/h1&gt;

&lt;p&gt;Create an application user in Dynamics 365 by going into Advanced Settings &amp;gt; Security &amp;gt; Users.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the screen change the view to Application Users.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5OAZUdMi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ohrklrlrovjq29dxmtd.png" alt="image"&gt;
&lt;/li&gt;
&lt;li&gt;Click on New.&lt;/li&gt;
&lt;li&gt;Put the client id (Step 1, 7) in the Application Id field of window. Then click on Save.&lt;/li&gt;
&lt;li&gt;Assign a security role by clicking on Manage Roles. For simplicity I have assigned mine to system admin.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  3. Code
&lt;/h1&gt;

&lt;p&gt;I created a class library with .NET 5 and then installed &lt;code&gt;Microsoft.Identity.Client&lt;/code&gt; (MSAL) through Nuget. The trick here is to know the scope for Dynamics 365. It is,&lt;br&gt;
&lt;code&gt;Dynamics 365 URL + / + “.default”&lt;/code&gt;&lt;br&gt;&lt;br&gt;
You can see the scope for my example in line 18 in the following gist,&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;To understand what scope is in MSAL flows, you can read about them &lt;a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-v1-app-scopes"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;If you want to see the whole project the code is found here,&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i3JOwpme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ImranCodeBug"&gt;
        ImranCodeBug
      &lt;/a&gt; / &lt;a href="https://github.com/ImranCodeBug/CodeBug.CDS.Net5.Connector"&gt;
        CodeBug.CDS.Net5.Connector
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>dataverse</category>
      <category>dynamics365</category>
      <category>cds</category>
      <category>msal</category>
    </item>
  </channel>
</rss>
