locked
Html web resource RRS feed

  • Question

  • I am using the Html web resource.

    I have to access the Crm REST api from that web resource. How can i access it.

    Tuesday, June 25, 2013 4:22 PM

All replies

  • Hi,

    You need to add the SDK rest javascript (which is provided in the SDK) as a web resource to your solution. Then on the form that you want to use rest, add a reference to this library (above your javascript library). You can then call the rest methods within this library.

    If I am using only one method from the library I sometimes cut and paste the method from the SDK and include it in my form library.

    Chris

    Tuesday, June 25, 2013 4:47 PM
  • I add the jquery library in the html web resource.

    function setData() {

        //Get the context.
        var context = GetGlobalContext();

        //Get the url.
        var serverUrl = context.getServerUrl();

        var endpoint = "/XRMServices/2011/OrganizationData.svc";

        var entity = "/ProductSet";

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: "http://www.google.co.in/",
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            success: function (data, textStatus, XmlHttpRequest) {

                alert(data);
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                var error = window.JSON.stringify(XmlHttpRequest);
                document.write("error" + error);
            }
        });
    }

    In success it giving the empty string [""].


    Tuesday, June 25, 2013 4:53 PM
  • The url: "http://www.google.co.in/",

    I believe should instead be

    serverurl + endpoint + entity

    The url should be the ODATA url where u need to submit the request to.

    Perhaps changing the url should get this working.

    HTH

    Sam


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, June 26, 2013 3:53 AM