I am running into a very strange anomaly when I retrieve a date from one form, and set it on another based on the selection of records from a drop down bar.
The date in another form that was saved and set there via the date time picker, in this example, is 6/13/1943
My javascript pulls it and tells me via alert the value is this: /Date(-837979200000)/
My function below processes this and ultimately seeks to set the date in a new date time picker field on this new form.
However, it doesn't set the correct 6/13/1943 date in the new date time picker field and instead sets a bad date of 7/21/1996 which is a far cry from 6/13/1943
If I don't append the date value with ".match(/\d+/)[0] * 1" I get an error because the data is not in the right format for setting the new date time picker field.
What the heck am I doing wrong?
Any help is greatly appreciated.
function getDateLookupDetails(lField, dsName, gField1, sField1) { //lField - the name of the lookup field //dsName - the name of the dataset or form that the lookup field links back to //gField - the name of the field in the linkback dataset that we want to get data from //sField - the name of the file on the current form where we want to write the value that we pulled from the dataset into var lookUpObjectValue = Xrm.Page.getAttribute(lField).getValue(); if ((lookUpObjectValue != null)) { var lookuptextvalue = lookUpObjectValue[0].name; var lookupid = lookUpObjectValue[0].id; var serverUrl = Xrm.Page.context.getServerUrl(); //The XRM OData end-point var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; var odataSetName = dsName; var odataSelect = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + lookupid + "')"; $.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_data = data.d; //alert(result_data[gField1]); // Xrm.Page.getAttribute(sField1).setValue(result_data[gField1]); if ((result_data[gField1]) != null) { Xrm.Page.getAttribute(sField1).setValue(new Date(result_data[gField1].match(/\d+/)[0] * 1)); } else {Xrm.Page.getAttribute(sField1).setValue(null);} }, error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); } }); } }