简体   繁体   中英

How do you have multiple javascript libraries in Dynamics CRM 2011

Right I am creating a method which adds an Account to Dynamics CRM with an Ajax POST to a built in webservice, the code is as follows :

var context = GetGlobalContext();
var serverUrl = context.getServerUrl();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

var account = new Object();
account.Name = "Sample Account created via OData jQuery library.";

// Parse the entity object into JSON
var jsonEntity = window.JSON.stringify(account);

// Asynchronous AJAX function to Create a CRM record using OData
$.ajax({ type: "POST",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: serverUrl + ODATA_ENDPOINT + "/AccountSet",
    data: jsonEntity,
    beforeSend: function (XMLHttpRequest) {
        //Specifying this header ensures that the results will be returned as JSON.
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
    },
    success: function (data, textStatus, XmlHttpRequest) { },
    error: function (XMLHttpRequest, textStatus, errorThrown) { }
});

Right this code has a link to JSON and JQuery libraries, how do i link them in dynamic CRM 2011.

I am looking to execute the code on a onload function to add the new account. But am in the dark at the moment to how that will work.

I understand I have to first:

  • Go to web resources
  • Add the above jquery
  • save the file
  • Go to my entity and add the javascript library and its method to call on the onload

but it links to json and jquery libraries though. How does this work?

Just upload those libraries as additional Web Resources. On the customizations for the form, you can choose which libraries get loaded on the form. Just make sure your JSON and jQuery libraries are loaded before your custom code, and you should be fine.

Make sure all other depending JavaScipt libraries are loaded before this javascipt and you have to maintain the depending javascript precedence. Since you are using Json and JQuery libraries you have to load those libaries first. Also if you are using any function of some other library it has to be loaded (it should be in the top of the list) before this javascript.

使用像Jingo.js这样的JS Package / Dependency管理器

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM