[英]Display Custom text in HTML Page when date value is null
I have a Gantt Chart which is used to show the Project Timeline.我有一个甘特图,用于显示项目时间表。 I am using Google Charts to display the Gantt Chart.
我正在使用 Google Charts 来显示甘特图。
I am using this Gantt chart in VisualForce page to get the date values from Salesforce.我在 VisualForce 页面中使用此甘特图从 Salesforce 获取日期值。
Below is my logic:以下是我的逻辑:
<apex:page standardController="Project__c">
<apex:form >
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['gantt']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Task ID');
data.addColumn('string', 'Task Name');
data.addColumn('date', 'Start Date');
data.addColumn('date', 'End Date');
data.addColumn('number', 'Duration');
data.addColumn('number', 'Percent Complete');
data.addColumn('string', 'Dependencies');
data.addRows([
['Research', 'Find sources',
new Date("{!Project__c.GLI_Planned_Date__c}"), new Date("{!Project__c.GLI_Actual_Date__c}"), null, 100, null],
['Write', 'Write paper',
new Date("{!Project__c.REG_Planned_Date__c}"), new Date("{!Project__c.REG_Actual_Date__c}"), daysToMilliseconds(3), 25, 'null'],
['Cite', 'Create bibliography',
new Date("{!Project__c.UAT_Planned_Date__c}"), new Date("{!Project__c.UAT_Actual_Date__c}"), daysToMilliseconds(1), 20, 'null'],
['Complete', 'Hand in paper',
new Date("{!Project__c.STP_Planned_Date__c}"), new Date("{!Project__c.STP_Actual_Date__c}"), daysToMilliseconds(1), 0, 'null'],
['Outline', 'Outline paper',
new Date("{!Project__c.ARC_Planned_Date__c}"), new Date("{!Project__c.ARC_Actual_Date__c}"), daysToMilliseconds(1), 100, 'null']
]);
var options = {
height: 400,
gantt: {
trackHeight: 30
}
};
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
</apex:form>
</apex:page>
For few records, the date fields are null.对于少数记录,日期字段为 null。 Due to that, I am seeing the error
因此,我看到了错误
Cannot read property 'datefield' of undefined
无法读取未定义的属性“日期字段”
Is there any way that I can display some custom banner like "Required date values are not available" instead of the above error in case of missing date values?有什么方法可以显示一些自定义横幅,例如“所需的日期值不可用”,而不是在缺少日期值的情况下出现上述错误?
You have to validate the datefield if it is undefined, for example如果日期字段未定义,您必须验证它,例如
var datefield = (typeof !== 'undefined') ? datefield : 'some default value';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.