Monday, February 23, 2015

How to update the Parent data when child record is created/Updated/Deleted



function DisplayTotal() {


 if (Xrm.Page.ui.getFormType() == 2) 
 {
 var OpportunityId = Xrm.Page.data.entity.getId();
 var Total=0;
    if (OpportunityId != null) 
{
        var Opportunity = GetTotalLineItemValue(OpportunityId);
  if (Opportunity != null && Opportunity.length>0 && Opportunity[0].results != null && Opportunity[0].results.length>0) 
  {
for (var count = 0; count < Opportunity[0].results.length; count++) {
// alert(Opportunity[0].results[count].ExtendedAmount.Value);
Total= parseFloat(Total) + parseFloat(Opportunity[0].results[count].ExtendedAmount.Value);
          //alert(Opportunity[0].results[count].LastName);
 
}  

Xrm.Page.getAttribute("new_totalmyamt").setValue(Total);

  } 
 } 
 }
}

function GetTotalLineItemValue(OpportunityId) {
    var serverUrl = Xrm.Page.context.getServerUrl();
    
var oDataUri = serverUrl + "/xrmservices/2011/OrganizationData.svc/OpportunityProductSet?$select=ExtendedAmount&$filter=OpportunityId/Id eq guid'" + OpportunityId + "'";

    var jSonArray = new Array();

    jQuery.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: oDataUri,
        async: false,
        beforeSend: function (XMLHttpRequest) {
            //Specifying this header ensures that the results will be returned as JSON.            
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, XmlHttpRequest) {
            if (data && data.d != null) {
                jSonArray.push(data.d);
            }
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert("Error :  has occured during retrieval of the Account details");
        }
    });

    return jSonArray;
}

No comments:

Post a Comment

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...