How do I use an external Javascript library in CRM Dynamics?

1.5k views Asked by At

I'll be doing some REST-ing and oData-ing so I got the executable from DataJS project. I've added the file datajs-1.0.3.min.js as a web resource and my own qwerty.js as another one. So, I've ended up with two web resources called:

  1. CRMKonsulterna_MyOwnStuff
  2. CRMKonsulterna_TheCoolStuff

The problem is now that when I execute the code snippet below from web resource 1 that I've found on their site, I get a crash telling me that:

Field: window

Event: onload

Error: 'OData' is undefined

var shazoo = function () {

  alert("Commenced...");

  OData.read(
    "http://services.odata.org/Northwind/Northwind.svc/Categories",
    function (data) {
      var html = "";
        $.each(data.results, function (l) { 
          html += "<div>" + l.CategoryName + "</div>";
        });
        $(html).appendTo($("#target-element-id"));
    }
  );

  alert("Completed.");

}

How can I refer from a method inside web resource 1 to a method inside web resource 2? I've found this discussion but it didn't give me much. I can't even tell if it's helpful if one understand what they're talking about.

EDIT

I've made some changes and went for trying if OData is known to my method like this.

alert(OData);

Expecting a null value, I was surprised to discover that it gave me {Object object} instead. So, I'm guessing the connection between web resources is made. Is it so? Also, still, how can I make the call to get me some oData formatted data?!

1

There are 1 answers

1
AudioBubble On BEST ANSWER

Have you added both libraries to the entity? It's not sufficient to add them only as web resources.

  1. Settings -> Solution ->
  2. {pick the solution} -> or Customizations -> Customize the System ->
  3. Components -> Entities -> {pick the entity} -> Forms -> {pick the form type}
  4. Form properties -> Form Libraries