[英]Dynamics CRM 2011: javascript, 'null' is null not an object. error
我在Dynamics CRM 2011上使用JavaScript。我试图通过比较两个日期字段来创建一个新字段。 但是,我认为null值有问题。 出现cas错误消息:'null'为null不是对象。
以下是脚本。 请看看,让我知道您的想法。
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");
}
同样很可能默认值为null。 cas什么也没有显示。
非常感谢。
您的代码中有一些错别字,但是您可以用这种方式重写代码并填写缺少的操作。
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.