2012-12-03 53 views
0

我有以下的更新記錄:Dynamics CRM JavaScript:由於CreatedOn無法更新記錄?

var currentTimeBeingTracked = getCurrentTimeTracked(); 

if (currentTimeBeingTracked != null) { 
    currentTimeBeingTracked.dagency_EndDateTime = new Date(); 

    var jsonTrackedTime = window.JSON.stringify(currentTimeBeingTracked); 

    $.ajax({ type: "POST", 
     contentType: "application/json; charset=utf-8", 
     datatype: "json", 
     url: ODataPath + "/dagency_trackedtimeSet", 
     data: jsonTrackedTime, 
     beforeSend: function (XMLHttpRequest) { 
      XMLHttpRequest.setRequestHeader("Accept", "application/json"); 
     }, 
     success: function (data, textStatus, XmlHttpRequest) { 
      var newTimeTracked = data.d; 
      RetrieveTrackedTimes(); 
      alert("Stopped tracking your time successfully."); 
      window.top.document.getElementById("contentIFrame").contentWindow.location.reload(); 
     }, 
     error: function (XmlHttpRequest, textStatus, errorThrown) { 
      debugger; 
      alert("Couldn't stop tracking your time. " + XmlHttpRequest.responseText); 
     } 
    }); 
} 

但我不斷收到這樣的信息:

錯誤處理請求流。將 值從屬性'CreatedOn'的請求有效內容轉換爲類型 'DateTime'時遇到錯誤,該屬性是屬性的預期類型。有關更多詳細信息,請參閱內部例外 。

要創建的記錄,我用下面的代碼完美的作品:

var trackedTime = new Object(); 

var timeEntryName = prompt("Please enter a name for the tracked time:", "New time entry"); 
if (!timeEntryName) { 
    return false; 
} 

var isBillable = confirm("Is this task billable? If Yes, press OK."); 

trackedTime.dagency_name = timeEntryName; 
trackedTime.dagency_StartDateTime = new Date(); 
trackedTime.dagency_Billable = isBillable; 

var slot = new Object(); 
slot.Id = crmForm.ObjectId; 
trackedTime.dagency_Slot = slot; 

var jsonTrackedTime = window.JSON.stringify(trackedTime); 

$.ajax({ type: "POST", 
    contentType: "application/json; charset=utf-8", 
    datatype: "json", 
    url: ODataPath + "/dagency_trackedtimeSet", 
    data: jsonTrackedTime, 
    beforeSend: function (XMLHttpRequest) { 
     XMLHttpRequest.setRequestHeader("Accept", "application/json"); 
    }, 
    success: function (data, textStatus, XmlHttpRequest) { 
     var newTimeTracked = data.d; 
     RetrieveTrackedTimes(); 
     alert("Started tracking your time successfully."); 
     window.top.document.getElementById("contentIFrame").contentWindow.location.reload(); 
    }, 
    error: function (XmlHttpRequest, textStatus, errorThrown) { 
     alert("Couldn't start tracking your time. " + XmlHttpRequest.responseText); 
    } 
}); 

問題是什麼?我在哪裏可以找到消息引用的內部異常?

回答

2

更改爲這一點,它工作正常:

if (currentTimeBeingTracked != null) { 
    var trackedTimeUpdated = new Object(); 
    trackedTimeUpdated.dagency_EndDateTime = new Date(); 

    var jsonTrackedTime = window.JSON.stringify(trackedTimeUpdated); 

    $.ajax({ type: "POST", 
     contentType: "application/json; charset=utf-8", 
     datatype: "json", 
     url: ODataPath + "/dagency_trackedtimeSet(guid'" + currentTimeBeingTracked.dagency_trackedtimeId + "')", 
     data: jsonTrackedTime, 
     beforeSend: function (XMLHttpRequest) { 
      XMLHttpRequest.setRequestHeader("Accept", "application/json"); 
      XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE"); 
     }, 
     success: function (data, textStatus, XmlHttpRequest) { 
      var newTimeTracked = data.d; 
      RetrieveTrackedTimes(); 
      alert("Stopped tracking your time successfully."); 
      window.top.document.getElementById("contentIFrame").contentWindow.location.reload(); 
     }, 
     error: function (XmlHttpRequest, textStatus, errorThrown) { 
      debugger; 
      alert("Couldn't stop tracking your time. " + XmlHttpRequest.responseText); 
     } 
    }); 
} 

有什麼問題是,我需要設置X-HTTP-法合併,在URL中指定的GUID。