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)

Xrm.Page.data.save().then not calling error callback when plugin throws InvalidPluginExecutionException

(0) ShareShare
ReportReport
Posted on by

Using CRM 2016 Online

I'm trying to catch the InvalidPluginExecutionException in javascript.  I've seen older posts on this issue, but nothing more recent.

I have a contact plugin that throws the above exception.

The simplified plugin code is

protected void ExecuteContact(LocalPluginContext localContext)
{
  throw new InvalidPluginExecutionException(OperationStatus.Failed, -2136989695,
                "My Error Message");
}

In JavaScript, I'm calling Xrm.Page.data.save().then as such

Xrm.Page.data.save().then(
  function() {
    // handle save success
    
    // Do post save stuff
  },
  function(e) {
    // handle failure
    // expect to see e.errorCode and e.message of what was set in the 
    // InvalidPluginExecutionException
  }
);

 

I'm expecting the error callback to be called and have the e.errorCode and e.message contain the error code and error message, but what I'm seeing is the success callback always gets called.

When I debug the plugin using the profiler (https://community.dynamics.com/crm/b/crminogic/archive/2012/06/11/how-to-debug-plugins-using-profiler), I see the error callback getting called but the e.message contains the profiler debug text (which isn't surprising since we're under the profiler) and stepping through the debugger I know that the InvalidExecutionException is getting thrown.

What would cause the success handler to get called even when there is an InvalidExecutionException from the plugin?

Thanks

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    I am having the same problem. Does anyone have any suggestion on this?

  • Goutham A Profile Picture
    2 on at

    Hi,

    Under what event the plugin is registered and  which stage of plugin throws Invalid Plugin execution

    Can you see if the breakpoint is going to success state once?

  • Community Member Profile Picture
    on at

    Thanks for responding.  I had multiple plugins with various async and sync steps.  I wanted to be sure that multiple plugins weren't interfering so I unregistered these plugins and created a new plugin.

    All the new plugin code does is execute and throw an exception:

    protected void ExecuteContact(LocalPluginContext localContext)
    {
      throw new InvalidPluginExecutionException("My Error Message");
    }


    The good news is that the failure callback is now getting called

    Xrm.Page.data.save().then(
      function() {
        // handle save success
    
    
      },
      function(e) {
        // handle failure
        // WHA HOO!!!  Handler getting called
      }
    );


    Unfortunately, after the code executes in the error callback, the "Business Process Error" dialog appears.

    Is there anyway to suppress this dialog?  I want to be able to throw InvalidPluginExecutionException exceptions and catch them in my javascript code and not have this general crm error dialog to appear.

    Is there a global setting or flag to set somewhere?

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    AFAIK you can't change that behavior.

  • Community Member Profile Picture
    on at

    Thanks.

  • ashlega Profile Picture
    34,477 on at

    Hm.. thought there was more to that "thanks" just a minute ago.. so will just leave the comment below:

    I think your last conclusion is incorrect:)

    If you want to catch that error in javascript, you have to stop using "save/refresh".  Instead, you need to use Web API methods to update data in CRM.

    Save/Refresh methods are sort of wired to that exception, and the purpose of that "wiring" is not to let you override it, but to display the exception to the user whenever it happens.

  • Community Member Profile Picture
    on at

    I started a new thread and edited this thread to just "Thanks".  Thank you for your reply, I guess I just wouldn't expect an api call to display a dialog for me, especially an ugly dialog that I have no control over the styling or the content.

    We really should be able to suppress the dialog with saveOptions we pass to Xrm.Page.data.save(saveOptions).  

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