Hi, my OData and Javascript seem to be failing here. Towards the end of the alert I receive an "Object Object" alert. Essentially what I am trying to do is this:
I have a Lookup attribute in Phone activity entity called "new_billtype" which looks up a record from an entity I created called: Timesheet. When I lookup a timesheet record, I also want to automatically add the value held in "new_rate" field (also in the timesheet entity) and insert it back into the Phone Activity record in the field "new_charge". The problem I have is the code below works until the end where I get an alert that says "Object object".
Any help to fix this mess will be very appreciated.
function getBillDetails(){
var lookUpObjectValue = Xrm.Page.getAttribute("new_billtype").getValue();
if ((lookUpObjectValue != null))
{
var lookuptextvalue = lookUpObjectValue[0].name;
var lookupid = lookUpObjectValue[0].id;
alert(lookupid);
var serverUrl = Xrm.Page.context.getServerUrl();
//The XRM OData end-point
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var odataSetName = "wse_timesheetSet";
var odataSelect = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + lookupid + "')";
alert(odataSelect);
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: odataSelect,
beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
success: function (data, textStatus, XmlHttpRequest) {
var result_service= data.d;
var ratevar = result_service.wse_name;
alert(ratevar);
Xrm.Page.getAttribute("new_charge").setValue(ratevar);
},
error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
});
}
}