Hi,
I have written some code in javasript.
function calculateVehicleCost ()
{
var id =Xrm.Page.data.entity.getId();
var odataSelect = "/" + Xrm.Page.context.getOrgUniqueName() + "/XRMServices/2011/OrganizationData.svc" + "/" + "new_vehiclesSet?$filter=new_opportunity/Id eq guid'" + id + "'";
$.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 cost = null;
for (var i = 0 ; i < data.d.results.length; i++)
{
alert (data.d.results[i].new_CostperVehicle.Value);
cost = cost + data.d.results[i].new_CostperVehicle.Value;
}
alert (cost);
Xrm.Page.getAttribute("new_cost").setValue(cost);
//Xrm.Page.getAttribute("new_cost").setValue(parseFloat(eval(cost)));
Xrm.Page.data.entity.attributes.get("new_cost").setSubmitMode("always");
},
error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + textStatus + errorThrown + odataSelect); }
}
);
}
but the cost variable showing value "null1.00001.0000"
It is not doing addition of null+1.0000+1.000 and just appends one string to another.
Is there loophole in code or any other way to do this.
Thanks
Dilip
*This post is locked for comments