gmaniac
gmaniac

Reputation: 959

Microsoft Dynamics CRM display error returned from plugin through javascript

I am using Microsoft Dynamics CRM (off premise)

Microsoft Dynamics® CRM Online Spring '14 (6.1.0.575)

Via the javascript SDK making a call to create an entity which fires off a plugin. We do our custom validations in the plugin in pre-validation.

Javascript create call example from here -> http://msdn.microsoft.com/en-us/library/gg334427.aspx

//Create the Account
SDK.REST.createRecord(
  account,
  "Account",
  function (account) {
    writeMessage("The account named \"" + account.Name + "\" was created with the AccountId : \"" + account.AccountId + "\".");
    writeMessage("Retrieving account with the AccountId: \"" + account.AccountId + "\".");
    retrieveAccount(account.AccountId)
  },
  errorHandler
);

And then I can handle the error using that errorHandler function, like this:

function errorHandler(error) {
   writeMessage(error.message);
}

However, I am trying to get the error to display in the CRM error dialog box from InvalidPluginExecutionException. It displays it when I create the entity from a form, but when I make the call through javascript I can't seem to get it to display in the CRM error dialog box. I want to keep with the CRM theme, not use alert() in javascript, and have users be able to download the full exception that we are sending back.

Is it possible to call the dlg_error.aspx page in CRM and populate it with our error message? I am grasping at straws right now, anything would help out a lot. Thanks!

Upvotes: 1

Views: 3710

Answers (2)

Scorpion
Scorpion

Reputation: 4585

If you are using CRM 2013, I would suggest you to use Workflow instead of JavaScript to create record.

  1. Create a new workflow and un-tick the checkbox "Run this workflow in backgroung (recommended)".

enter image description here

  1. Create record from newly created workflow.
  2. Save and publish the record.
  3. Now go the the ribbon and select 'Run Workflow'.
  4. Select the newly created workflow and click 'Add'.
  5. If there is an error thrown by Plugin, It will be displayed in standard CRM Error dialog box which will allow you to download the log file.

enter image description here

Upvotes: 3

Zare
Zare

Reputation: 73

You can try to execute a synchronous jQuery ajax method, without catching error and see what happens. Creating a record from jScript you are using RESTful endpoint of CRM service, I am not sure if the error is going to be promoted in the same way. Try to use Fiddler if you would like to try opening error dialog yourself. Using new synchronous workflow feature might also do the trick.

Upvotes: 0

Related Questions