Wednesday, 21 November 2018

filter with parent opportunity id using Odata query Dynamic CRM.

How to get contact information by using ParentCustomerId from Opportunity entity

Description:

In this example, we explain that how to filter with parent opportunity is using OData service in Dynamic CRM.or how to get or filter record based on parent opportunity using OData in Dynamic CRM.or OData query to get some parent field in Dynamic CRM.or using OData query to determine whether specific entity has children or not in Dynamic CRM.

So below is the JavaScript code with OData query to fetch or filter record with parent opportunity in Dynamic CRM.
Code:

  function CalculateDelataForOpportunity()
  {
  var opportunityId = Xrm.Page.data.entity.getId();
                    
        CalculateDelata(opportunityId); 
  }

 function CalculateDelata(opportunityId) {
            debugger;
          
var ChildOpportunityRevenueTotal = 0;
            var oDataUri = Xrm.Page.context.getClientUrl() + "/xrmservices/2011/OrganizationData.svc/OpportunitySet?$filter=ent_ParentOpportunity/Id eq Guid'" + opportunityId.replace("{", "").replace("}", "") + "'&$select=ActualValue";
            //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) {
                    for (var i = 0; i < data.d.results.length; i++) {
                      ChildOpportunityRevenueTotal = ChildOpportunityRevenueTotal + Number(data.d.results[i].ActualValue.Value);
                    }
                                                            var actualvalue=Xrm.Page.getAttribute("actualvalue").getValue();
                                                            var DeltaValue=actualvalue-ChildOpportunityRevenueTotal;
                                                            Xrm.Page.getAttribute("actualvalue").setValue(ChildOpportunityRevenueTotal);
                                                            Xrm.Page.getAttribute("new_mprcontractresidualvalue").setValue(DeltaValue);        

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {}
            });
        }

2 comments:

  1. Playtech casino game for real money
    Slot machine for 서울특별 출장샵 real money. You 목포 출장마사지 can play your favorite slots, 남양주 출장안마 poker, 군산 출장안마 and other games in this 태백 출장마사지 casino game, which allows you to play casino games for real

    ReplyDelete