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