Plugins in Dynamics 365 : Part 3

Hello Guys,

In my previous blogs i have shown plugin execution pipeline.Today we will be exploring more about plugins with some handy exercise also we will see how to register plugin in CRM. But before if you are new to our blog then do follow us to know more about Dynamics and Power Platform. Also if you like our blog then please comment and share this blog with your friends.

Today we will create one plugin which will validate some attribute of Contact entity.



For example, Contact record should be having Account associated with it, Email and contact details should be validated,First Name and Last Name should not contain "Test" value.We will be working with the same project which we have created earlier in the series of Plugin Blog.



Right click on the project and Add a new class file. Name this file as "ContactValidation". Inherit this class with base class named "IPlugin" and implement all the abstract methods.



IServiceProvider interface contains one method and it is GetService() which can be used to get Context. Now first of all we will understand what Context is and how we can retrieve it.

Context provides contextual information regarding to that plugin execution. While developing plugin you need to know the execution process like, what is happening at client side, what record is being processed, record belongs to which entity, plugin is registered for which message etc. For getting these all details we need to use IPluginExecutionConext which can be retrieved by using "serviceProvider" parameter passed to the Execute method.



Context will give you below contextual details:
  • Context.InputParameters[“Target”]
  • Context.PreEntityImages
  • Context.PostEntityImages
  • Context.MessageName
  • Context.Stage etc.
You can visit this MSDN link for more details. For time being we will implement our validation on Contact entity. Modify the code as below:




Now build the project. So our plugin is ready for registration. For registering plugin we need plugin registration tool. From the start menu open Power shall script editor and paste below scripts:

$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = ".\nuget.exe"
Remove-Item .\Tools -Force -Recurse -ErrorAction Ignore
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose
./nuget install Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool -O .\Tools
md .\Tools\PluginRegistration
$prtFolder = Get-ChildItem ./Tools | Where-Object {$_.Name -match 'Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool.'}
move .\Tools\$prtFolder\tools\*.* .\Tools\PluginRegistration
Remove-Item .\Tools\$prtFolder -Force -Recurse

The above script will download plugin registration tool.



Now we will register our plugin.

Step 1:- Open Plugin Registration Tool.



Step 2:- Click on create a new connection. Click on Login.



Step 3:- Enter your credentials and click Next.



Step 4:- Click on register new assembly.



Step 5:- Specify the path of the DLL. and click on Register.



Now we will register the steps:

Step 6:- Select plugin which you registered. Right click on that assembly and select Register new step. It will open a new window. Fill details as below:



Step 7: Click on Register new step.

Now our step is registered. We will check our validation is working or not. Open Dynamics CRM and try to create a new contact record.







Hope it helps...


Comments

  1. Your blog is very hard to find. the name in the link and the name at the banner are different. This leads to a lot of confusion. Consider changing that and also adding some meta data. Your content is great. If you add these few touches your audience will jump up considerably.

    ReplyDelete
    Replies
    1. Thanks for you response Humzah. i will consider your points and will do modification.

      Delete

Post a Comment

Popular posts from this blog

Read Only Sub Grid & Editable Sub grid in Dynamics 365

Using Pipelines in Power platform for deploying solutions to environments.

Understanding Sales Process in D365.