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)

Stop record creation from Pre-validate Plugin without throwing exception

(0) ShareShare
ReportReport
Posted on by 93

Hello Techies, 

I have a pre-validate plugin for duplicate detection.

based on the criterion if there is duplicate records found, I want to stop the record creation without throwing the Invalid Plugin Execution Exception.

Thanks in Advance. 

Viswa

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    jlattimer Profile Picture
    24,562 on at

    You'd probably be better off moving your code to a plug-in which is registered on a custom action and then call the custom action using JavaScript when the form saves. This way you can get back an error message and display it in a friendly way to the end user.

  • Viswanath Profile Picture
    93 on at

    Hello Jason,

    Thanks for reply.

    Records willbe created/updated from external systems but not manullay.

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at

    In this case use you have to throw an exception.

  • Viswanath Profile Picture
    93 on at

    In this case the source will receive the exception but client doesn't want it, as this is just a duplicate and wanted just to ignore.  

  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi Viswanath,

    This is how you can do it with C# code.

    var context = (IPluginExecutionContext) serviceProvider.GetService(typeof (IPluginExecutionContext));
    if (context.Stage == 10) //Pre-validation { //Stop Pre-validation code execution without throwing an exception } else if (context.Stage == 20) //Pre-operation { //Execute Pre-operation code } else if (context.Stage == 40) //Post-operation { //Execute Post-operation code }
  • Suggested answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at

    Probably you can give the option to the external system for checking if the record already exists & ignore it before creating.

    You have choice of creating alternate key, UPSERT operation or SuppressDuplicateDetection to decide. Better to stay away from prevalidate Plugin & InvalidPluginExecutionException.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    If you are from external exe, actually you can wrap the code using block try and catch to surpress the error if you've got error unique right? It should be got error if you still want to have unique data insert into your system and not creating the error. It means that your code works normally.

  • Viswanath Profile Picture
    93 on at

    Hello Adrian,

    I have written some duplicate detection code and if I found records I want to stop execution without throwing exception, which mean record shouldnt get created.

  • Viswanath Profile Picture
    93 on at

    Any other approach like Abort() in C# threading ? 

  • Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    If you don't want to get error stopper. Actually the easiest way is doing this one:

    try{

    service.Create(entity);

    }

    catch(Exception ex){

    //Surpress the error weather got problem or not

    }

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