locked
how to return value from ajax json in CRM 2013 RRS feed

  • Question

  • Hi,

    i want to return address field from getAssest function.

    My code is as below:

    function getAsset() 
    {
    
    
    var pagecontext = Xrm.Page.context;
    var serverUrl = pagecontext.getServerUrl();
    var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
    var oDataSelect = oDataPath + "/new_assetSet?$select=new_asset,new_RoadName,new_City,new_PostCode";
    
    $.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: oDataSelect,
    
    beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
    
    success: function (data, textStatus, XmlHttpRequest) {
    var results = data.d.results;
     var address = ''; 
    for( i=0; i< results.length; i++)
    {
    address = address +','+ "'" + results[i].new_asset  +', ' + results[i].new_RoadName+', '+ results[i].new_City +', ' + results[i].new_PostCode+ "'"
    
    }
    address ='['+ address.substring(1, address.length) + ']';
    alert(address);
    },
    
    error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + oDataSelect ); }
    });
    
    }
    

    Thanks


    Wednesday, April 23, 2014 10:49 AM

All replies

  • Hi,

    Maybe this post can hel you:

    http://social.msdn.microsoft.com/Forums/en-US/3b93ab76-da1a-434d-8823-1f6fdafa2b76/how-get-created-record-id-of-crm-entity?forum=crm

    Bye

    A.G.


    Alessandro Graps

    Wednesday, April 23, 2014 11:20 AM
  • hi,

    in above link, i am not able to find as per my requirement.

    I can alert address var with in "success: function"  but i am not able to return address value from $.ajax function.

    Thanks

    Wednesday, May 7, 2014 8:33 AM
  • function GetMatchId(recordid, type) {
        var matchid = null;
        if (!!recordid) {
            var selectQuery = "dns_matchSet?$select=dns_matchId&$filter=";
            if (type == "dns_audit") {
                selectQuery += "dns_MatchEmployee";
            } else if (type == "contact") {
                selectQuery += "gab_MatchAuditor"
            }
            selectQuery += "/Id eq guid'" + recordid + "' and dns_MatchType/Value eq 810520006 and dns_Status/Value ne 810520002";
            var odataSelect = GetServerUrl() + selectQuery;
            //alert(selectQuery);
            $.ajax({
                type: "GET",
                async: false,
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: odataSelect,
                beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
                success: function (data, textStatus, XmlHttpRequest) {
                    var result = data.d;
                    if (!!result.results[0]) {
                        matchid = result.results[0].dns_matchId;
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert('OData Select Failed: ' + odataSelect);
                }
            });
        }
        return matchid;
    }

    see the blog

    http://makdns.blogspot.com/2013/04/crm-feed-parse-json.html

    http://makdns.blogspot.com/2013/08/ms-dynamics-crm.htm

    Wednesday, May 7, 2014 3:28 PM