From 69b581eb022daf6ef23851bfc6e4ebe2a22aaae9 Mon Sep 17 00:00:00 2001 From: Tom Patros Date: Thu, 13 Feb 2014 10:30:11 -0500 Subject: [PATCH 1/2] Added formatDateTime helper JS function RemoteTK didn't seem to support datetime fields. Part of supporting them is sending the datetime value in the right format, which this function does per the Apex docs. --- RemoteTK.component | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/RemoteTK.component b/RemoteTK.component index 071114a..71ba2bc 100644 --- a/RemoteTK.component +++ b/RemoteTK.component @@ -196,6 +196,26 @@ if (remotetk.Client === undefined) { escape: false }); } + + /* + * + * Helper function to ensure dates are properly formatted when using RemoteTK + * Per Apex docs: the specified string should use the standard date format “yyyy-MM-dd HH:mm:ss” in the local time zone. + */ + remotetk.Client.prototype.formatDateTime = function(jsDateObject) { + var output = jsDateObject.getFullYear() + '-'; + if(jsDateObject.getMonth() + 1 < 10) output += '0'; + output += jsDateObject.getMonth() + 1 + '-'; + if(jsDateObject.getDate() < 10) output += '0'; + output += jsDateObject.getDate() + ' '; + if(jsDateObject.getHours() < 10) output += '0'; + output += jsDateObject.getHours() + ':'; + if(jsDateObject.getMinutes() < 10) output += '0'; + output += jsDateObject.getMinutes() + ':'; + if(jsDateObject.getSeconds() < 10) output += '0'; + output += jsDateObject.getSeconds(); + return output; + } } - \ No newline at end of file + From c65b66c1df7f9785690f596471200404789ee4f0 Mon Sep 17 00:00:00 2001 From: Tom Patros Date: Thu, 13 Feb 2014 10:32:46 -0500 Subject: [PATCH 2/2] Added DateTime data type support in writeFields DateTime data type was missing. Addition of formatDateTime in RemoteTK.component helps ensure proper format is passed. --- RemoteTKController.cls | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RemoteTKController.cls b/RemoteTKController.cls index 859cd3a..71665b8 100644 --- a/RemoteTKController.cls +++ b/RemoteTKController.cls @@ -64,6 +64,9 @@ public class RemoteTKController { if (valueType == Schema.DisplayType.Date) { obj.put(key, Date.valueOf(svalue)); + } else if (valueType == Schema.DisplayType.DateTime) { + // per apex docs: the specified string should use the standard date format “yyyy-MM-dd HH:mm:ss” in the local time zone. + obj.put(key, DateTime.valueOf(svalue)); } else if (valueType == Schema.DisplayType.Percent || valueType == Schema.DisplayType.Currency) { obj.put(key, svalue == '' ? null : Decimal.valueOf(svalue)); @@ -291,4 +294,4 @@ public class RemoteTKController { return JSON.serialize(result); } -} \ No newline at end of file +}