0

我在 Dynamics CRM 2011 上使用 JavaScript。我试图通过比较两个日期字段来创建一个新字段。但是,我认为空值有问题。cas 错误消息出现:'null' is null not an object。

以下是脚本。请看看,让我知道你的想法。

function m1status() {

    var m1date = Xrm.Page.getAttribute("new_m1date").getValue()

    var today = Xrm.Page.getAttribute("new_todayis").getValue()

    if (m1date == null) {

        Xrm.Page.getAttribute("new_m1status").setValue('Not Booked');}

    else if (m1date.getTime() >= today.getTime()) {

        Xrm.Page.getAttribute("new_m1status").setValue('Booked');}

    else {

        Xrm.Page.getAttribute("new_m1status").setValue('Completed');}

    //Set the Submit Mode
    Xrm.Page.getAttribute("new_m1status").setSubmitMode("always");

}

也很可能默认值为空。cas什么都没有出现。

非常感谢。

4

1 回答 1

0

您的代码中有一些拼写错误,但是您可以通过这种方式重写您的代码并填写缺失的操作。

function m1status() {

    var m1date = Xrm.Page.getAttribute("new_m1date").getValue();
    var today = Xrm.Page.getAttribute("new_todayis").getValue();

    // you can have 4 cases
    // 1: both fields are null
    if (m1date == null && today == null) {
        Xrm.Page.getAttribute("new_m1status").setValue('Not Booked');
    }
    // 2: both fields are not null
    if (m1date != null && today != null) {

        if (m1date.getTime() >= today.getTime()) {
            Xrm.Page.getAttribute("new_m1status").setValue('Booked');
        }
        else {
            Xrm.Page.getAttribute("new_m1status").setValue('Completed');
        }
    }
    // 3: first field is not null, second field is null
    if (m1date != null && today == null) {
        // what need to do in this case?
    }
    // 4: first field is null, second field is not null
    if (m1date == null && today != null) {
        // what need to do in this case?
    }

    Xrm.Page.getAttribute("new_m1status").setSubmitMode("always");
}
于 2013-04-05T06:41:10.860 回答