简体   繁体   中英

JSON data in MS CRM 2011

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); }

To get response use "complete" function:

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

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