0

I'm having an issue using JOSN data in MS CRM 2011. I am using the correct REST syntax to pull the CRM data but my JavaScript is the remaining issue.

What I want to do is append data from my JSON to a class of my choosing. I checked the console and no errors are apparent. Originially I believed once I had the JSON object I could pull the data from it using jQuery. Here is the code I currently have:

RetrieveScoutMetadata : (function(scout_displayable){
var query = "/scout_metadataSet?$select=scout_data_type,scout_display_name,scout_display_order,scout_displayable,ImportSequenceNumber,scout_name,scout_metadataId&$orderby=scout_display_order asc&$filter=scout_displayable eq "+scout_displayable+"";
ExecuteQuery(query);
 })

RetrieveScoutOpportunity : (function(scout_account){
var query = "/scout_opportunitySet?$select=*&$filter=scout_account/Id eq guid'"+scout_account+"'";  
ExecuteQuery(query);
})

RetrieveScoutAccount : (function(scout_account){
var query = "/scout_accountSet?$select=*&$filter=scout_account/Id eq guid'"+scout_account+"'";
ExecuteQuery(query);
})

 //
 // ExecuteQuery executes the specified OData Query asyncronously
 //
 // NOTE: Requires JSON and jQuery libraries. Review this Microsoft MSDN article before 
 //       using this script http://msdn.microsoft.com/en-us/library/gg328025.aspx
 //
 function ExecuteQuery(ODataQuery) {

var serverUrl = Xrm.Page.context.getServerUrl();

// Adjust URL for differences between on premise and online 
if (serverUrl.match(/\/$/)) {
    serverUrl = serverUrl.substring(0, serverUrl.length - 1);
}

var ODataURL = serverUrl + "/XRMServices/2011/OrganizationData.svc" + ODataQuery;

 $.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: ODataURL,
    beforeSend: function (XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
    },
    success: function (data, textStatus, XmlHttpRequest) {
        //
        // Handle result from successful execution
        //
        // e.g. data.d.results
        alert("OData Execution Success Occurred");
    },
    error: function (XmlHttpRequest, textStatus, errorObject) {
        //
        // Handle result from unsuccessful execution
        //
        alert("OData Execution Error Occurred");
    }
});
$('.up-sell').append(account.scout_num_up_sells);
}

 //
 // Error Handler
 //
 function ErrorHandler(XMLHttpRequest, textStatus, errorObject)
  { alert("Error Occurred : " + textStatus + ": " + JSON.parse(XMLHttpRequest.responseText).error.message.value); }

1 Answer 1

0

To get response use "complete" function:

complete: function (jsondata, stat) {
                         if (stat == "success") {   
                             data = JSON.parse(jsondata.responseText);
                         }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.