0

我有以下内容来更新记录:

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

问题是什么?我在哪里可以找到消息所指的内部异常?

4

1 回答 1

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-Method 设置为 MERGE 并在 URL 中指定 guid。

于 2012-12-03T11:59:41.323 回答