web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Pre Validation Plugin

(0) ShareShare
ReportReport
Posted on by 15

How to create pre validation plugin

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Tim Dutcher Profile Picture
    2,100 on at

    Here's sample plug-in code: https://msdn.microsoft.com/en-us/library/gg594416.aspx

    For your plug-in, register it as pre-validation for the event pipeline stage.

    In the plug-in, you can throw exception InvalidPluginExecutionException if the data or conditions you are validating are incorrect, based on your business logic.

  • FidelMartin Profile Picture
    128 on at

    Hello,

    By using Plugin Registration’s Pre-Validation stage, we can validate or modify before the main operation occurs. Pre-validation stage will occur before the main operation executes.

    Here, we have given one example of how we can use the Pre-validation stage in plugin registration tools.

    For Example, we have given the Pre-validation on the Account entity, so whenever any account record is updated, it will update the Fax number as shown below.

    Follow the below steps :

    Step 1: Add the below code in your code editor for the plugin.

    using System; using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Xrm.Sdk;
    namespace Plugindemo
    {
    public class Prevlidationclass : IPlugin
    {
    public void Execute(IServiceProvider serviceProvider)
    {
    ITracingService tracingService =
    (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));
    if (context.InputParameters.Contains("Target") &&
    context.InputParameters["Target"] is Entity)
    {
    Entity entity = (Entity)context.InputParameters["Target"];
    try
    {
    if (entity.LogicalName == "account")
    {
    if (entity.Attributes.Contains("fax") == false)
    {
    entity.Attributes.Add("fax", "1122344343");
    }
    }
    }
    catch (Exception Ex)
    {
    //tracingService.Trace("Myplugin:{0}", Ex.ToString());
    throw new NotImplementedException(Ex.Message);
    }
    }
    }
    }

    Step 2: Now open the Plugin Registration Tool and connect the CRM where you want to add pre-validation operation.

    After connecting to the CRM, Click on Register, and there will be a label as Register New assembly.

    Step 0000s2
     

    Step 3: After clicking on Register New Assembly, it will open a pop-up to register assembly, in that pop-up, click on 3 dot (…) and select the .dll file for your project.

    Step0000s3
     

    After selecting the dll file, check the Select all checkbox and click on the Register Selected Plugin button.

    Step 4: Next, locate the assembly and add a new step by clicking the Register New Step.

    Step0000s4
     

    Step 5: Now, to register the new step, it will open a pop-up.

    Keep value as given below :

    Message: Update.

    Primary Entity: account

    Event pipelinestage of execution: Prevalidation step should be chosen.

    Step0000s5
     

    Note as this is pre-validation, it needs to be synchronous and cannot be asynchronous. After filling in the above details, click on the Update Step button.

    Step 6: Now, we can test this. On an account record, insert a fax number:

    Step0000s6
     

    Step 7: After saving and refreshing, we can see that our plugin has replaced the fax number. So whenever any account record is updated, it will update the fax number for that record.

    Step0000s7
     

    This is how a user can use the Pre-validation stage in the Plugin Registration tool to validate or modify something by plugin registration tool.

    If you have any query related please contact us.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans