Thursday 13 September 2018

Retrieve another entity record by using GUID of that record in Javascript.

Retrieve another entity record by using GUID of that record in Javascript

Description:
In this example, we explain that how to get all the record based on GUID in Dynamic CRM using JavaScript or jQuery. Or filter the records based on guid in Dynamic 365 CRM using JavaScript Ajax call. Or retrieve another entity record by using GUID of that record in JavaScript in Dynamic CRM.

So here, we explain that how to retrieved record by GUID in dynamic CRM using OData using JavaScript.
Code:

function getRecords(investorId) {
    debugger;
    var CurrentUnitOwned = 0;
    var CurrentPrice = 0;
    var CurrentInvestmentWorth = 0;
    var DividendReceived = 0;
    var ROIfromSharebuyback = 0;
    var ProfitLoss = 0;
    var PercentReturn = 0;
    var YieldPerYear = 0;
    var oDataUri = Xrm.Page.context.getClientUrl() + "/xrmservices/2011/OrganizationData.svc/new_opportunityaccountSet?$filter=new_opportunityaccountId eq Guid'" + investorId.replace("{", "").replace("}", "") + "'";
    // alert(oDataUri);
    $.ajax({
        type: "GET",
        async: false,
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: oDataUri,
        beforeSend: function(XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function(data, textStatus, XmlHttpRequest) {

            //alert("Unit " + data.d.results[0].new_UnitEngaged + " Length " + data.d.results.length);

            Xrm.Page.getAttribute("new_unitengaged").setValue(data.d.results[0].new_UnitEngaged);
            var BuyBackUnit = Xrm.Page.getAttribute("new_units").getValue();
            if (BuyBackUnit > data.d.results[0].new_UnitEngaged) {
                alert("You cannot buy more then " + data.d.results[0].new_UnitEngaged + " Units");
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {}
    });
}


0 comments:

Post a Comment