locked
Intermittent performance using rest end point in Javascript CRM 2011 RRS feed

  • Question

  • Hi there,

    I have used rest end point to createa  record from ribbon button click on a system form. It is working fine...but some times it doesn't work and again later it starts working. So there is a chance of creating unnecessary records but mistake.

    sample code

    function createRecord(concatenatedorders) {
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
        var CRMObject = new Object();
        /////////////////////////////////////////////////////////////
        // Specify the ODATA entity collection
        var ODATA_EntityCollection = "/skyscale_invoiceprocessingSet";
        //   alert("Entered the Odata entity point");
        /////////////////////////////////////////////////////////////
        // Define attribute values for the CRM object you want created

        CRMObject.skyscale_invoicegroup = concatenatedorders;
        CRMObject.skyscale_invoicebatch = { Id: invoiceBatchId, LogicalName: 'skyscale_invoicebatch' };
        CRMObject.skyscale_requesttype = { Value: requesttype };
     
         //    CRMObject.Telephone1 = "123";
        //  CRMObject.Fax = "456";
        //Parse the entity object into JSON

        var jsonEntity = window.JSON.stringify(CRMObject);
        // var jsonEntity = CRMObject;
        //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 + ODATA_EntityCollection,
            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) {
                alert("success");
                var NewCRMRecordCreated = data["d"];
                //      alert("CRM GUID created: " + NewCRMRecordCreated.skyscale_invoiceprocesssingId);
             },
     
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("failure");
            }
     
        });
     
    }

    Here I am bit confussed am I missing something or using rest end point is not that good advice

    FYI

    Environment : CRM 2011 on premise multitenant

    onload of the form: Jquery, json libraries

    when the functionality doesnt work, I do IIS reset, aynchronous reset but still doesn't work

    Kind Regards,


    SAMA

    Thursday, August 1, 2013 2:30 PM

Answers

  • Hi Guys,

    thanks for your time in looking into it! yes the code is right, it doesn't work sometimes because it is still in queue and not responding quickly as its async services. for better approach I have done plugin on create event, it works excellent without any delays. So I prefer plugins as better option.

    Regards


    SAMA

    • Marked as answer by Samartin Monday, September 2, 2013 11:21 AM
    Monday, September 2, 2013 11:21 AM

All replies

  • When you say "it doesn't work", do you mean:

    1. The code does not execute at all?

    2. The code executes but the record doesn't get created?

    I suggest you use IE dev tools to step through your code line by line (assuming you're testing in IE). Also try using fiddler to see where the request is failing.

    Friday, August 2, 2013 7:49 PM
  • Hi Roshan,

    Thanks for looking onto it....as you think even I was confident on this code been using it for long time.. it works really good. but not 100% as good as server side code like plugins...the rest end point function is called and in Ajax function it fails rarely it happens... but yes it fails once in a while..that is what I am bit worried....how to handle this to make running all times

    Cheers


    SAMA

    • Marked as answer by Samartin Monday, September 2, 2013 11:21 AM
    • Unmarked as answer by Samartin Monday, September 2, 2013 11:21 AM
    Tuesday, August 6, 2013 9:56 AM
  • Hi Guys,

    thanks for your time in looking into it! yes the code is right, it doesn't work sometimes because it is still in queue and not responding quickly as its async services. for better approach I have done plugin on create event, it works excellent without any delays. So I prefer plugins as better option.

    Regards


    SAMA

    • Marked as answer by Samartin Monday, September 2, 2013 11:21 AM
    Monday, September 2, 2013 11:21 AM