简体   繁体   English

Dynamics CRM 2011:javascript,“ null”为null不是对象。 错误

[英]Dynamics CRM 2011: javascript, 'null' is null not an object. error

I am using JavaScript on Dynamics CRM 2011. I am trying to create a new field by comparing two date fields. 我在Dynamics CRM 2011上使用JavaScript。我试图通过比较两个日期字段来创建一个新字段。 however, I think something is wrong with null value. 但是,我认为null值有问题。 cas error message shows up: 'null' is null not an object. 出现cas错误消息:'null'为null不是对象。

The following is the script. 以下是脚本。 Please have a look, and let me know what you think. 请看看,让我知道您的想法。

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

}

Also most likely the default value is null. 同样很可能默认值为null。 cas nothing is shown up. cas什么也没有显示。

Thanks so much. 非常感谢。

There are some typos in your code, however you can rewrite your code in this way and fill the missing actions. 您的代码中有一些错别字,但是您可以用这种方式重写代码并填写缺少的操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM