D365 – Pug-in Writing Code

So in our last blog “D365 – Create Plugin Template” we saw, how we can create a plug-in template in visual studio.

Now let us see how we can move forward and write plug-in code.

So, the idea is that when create a new Contact, the plug-in should fill the Personal Notes field automatically

When we create a Contact record and provide details (such as first name , last name, etc.):

  1. These details are captured by the ServiceProvider.
  2. The ServiceProvider has got the Context.
  3. In the Context we have InputParameters.
  4. InputParameters has got Target.
  5. We are extracting Target as an Entity.

So here the Entity is generic class, which means that it can be any Entity such as Contact, Account, Task, Case, etc.

You can access the attributes through this Entity. So add the following code in the Plug-in template code (try/catch section) and use the Contact attribute’s logical name.

  • To read from attribute values:
    • string firstName = entity.Attributes[“firstname”].ToString();
    • string lastName = entity.Attributes[“lastname”].ToString();
  • To assign data to attribute:
    • entity.Attributes.Add(“description”, “Hello World” + firstName + lastName);

Tip: You can get the logical name from the solution. If you want to save clicks you can use the following extension for chrome Level up for Dynamics 365/PowerApps.

1 thought on “D365 – Pug-in Writing Code”

  1. Hi sir, please make plugin videos in your youtube, honestly speaking your videos are very much helpful no one in youtube explains like you.
    Thanks,

Comments are closed.

Scroll to Top