No callback executed on `read` and an error received (exception thrown and not caught)

297 views Asked by At

In CRM Dynamics I'm executing the following code. I've tried to put it inside a try-catch statement to catch the allegedly uncaught exception but it makes no difference. I'm guessing that it occurs inside CRM server, C# code or something like that.

var temp = OData.read({
  urlOrRequest: "https://myurl/2011/OrganizationData.svc/crmk_CustomEntitySet",
  success: function(dataSet) { alert("Yippi!"); },
  error: function(errorMessage) { alert("Buuuu..."); },
  handler: null,
  httpClient: null,
  metaData: null
});

Of course, I've tested to execute the https://myurl/2011/OrganizationData.svc/crmk_CustomEntitySet call and it resturns the data as supposed to, so apparently I've got connection and access right in order.

However, I get neither of the callbacks to execute. Everything is just ghostly quiet. As I attempt to close or reload the page, though, I get an error message from CRM Dynamics, the partial contents of which are listed below.

<ScriptErrorDetails>
  <Message>Exception thrown and not caught</Message>
  <Line>13</Line>
  <URL>/%7B634854498230000000%7D/WebResources/crmk_MyResourceWithDataJS</URL>
  <PageURL>/userdefined/edit.aspx
    ?etc=10008&pagemode=iframe&preloadcache=1349853066209</PageURL>
 <Function></Function>
 <CallStack></CallStack>
</ScriptErrorDetails>

Given my competence level with CRM Dynamics (low) and with DataJS package (loooow), I'm stuck having no clue as to why it doesn't work nor how to trouble-shoot it.

I've checked out every example I could find on their page

1

There are 1 answers

1
AudioBubble On

You're getting no callback execution because you're not sending in one. You think you do but you don't. You're using the JSON syntax putting the properties (or whatever they're called) in an object. You're intending the following list of inputs.

  1. The URL to organization data.
  2. A function telling what to do if successful.
  3. A function telling what to do if failed.
  4. A bunch of nulls.

But since you package it into a structure, the CRM sees the following (regarding the full signature of the function odata.read(...) as seen in the source file..

  1. An object with some stuff in it, not constituting a parsable URL.
  2. Nothing at all, meaning null, while CRM wants to see a function (success).
  3. Nothing at all, meaning null, while CRM wants to see a function (fail).
  4. Nothing at all, meaning null, while CRM wants to see a function (serialization).
  5. Nothing at all, meaning null, while CRM wants to see a HTTP client layer (whatever that might be).
  6. Nothing at all, meaning null, while CRM wants to see some metadata.

Then a crash occurs inside the CRM server (since you failed to provide a parsable URL to the organization data that you're trying to read) and an exception is being thrown. But you haven't provided a callback function for receiving the notification of such an error, which is the message you've mentioned.

Your try-catch doesn't catch anything since there's no exception to catch. It's already been caught inside CRM Dynamics server. What you see is that it complains that there's no function to be called for notifying you about that.

Try to execute an equivalent to this code and see if you're successful (or at least get another error message).

var temp = OData.read(
  "https://myurl/2011/OrganizationData.svc/crmk_CustomEntitySet",
  function(dataSet) { alert("Data retrieval successful."); },
  function(errorMessage) { alert("Operation failure!"); }
});

I'm assuming that you're using an other URL than what you've shown us in your code sample. It's just an example, right? You can test pasting in the very URL into IE and see if you'll get a reply and what it contains.