function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
beenerbeener 

Time Stamping a record using javascript and an s-control

Hi All,

Question #1:
I have written the followin Javascript code, implemented in an Execut Javascript s-control.
The Idea is to time stamp a record.

However, the date assignment (Line 3 in the code) doesn't work. the field type is date (not date/time).
I've tried wrapping
{!TODAY()} twith single quotes, double quotes, and without any quotes. each delivers a different error. but no results.


Code:
var temporal= new sforce.SObject("Contact"); 
temporal.id = '{!Contact.Id}'; 
temporal.Audited_date__c={!TODAY()};//***this line doesn't work***
temporal.Audited_by__c = "{!$User.Alias}" result = sforce.connection.update([temporal]); window.parent.location.href="{!URLFOR($Action.Contact.View,Contact.Id,null , true )}";



Question #2:
Is there a way to reload only that field (save the page refresh)?

Any help would be much appreciated.
Thanks


Message Edited by beener on 10-28-2008 09:52 AM
CaptainObviousCaptainObvious
Try:  temporal.Audited_date__c= new Date();
 
To update the field without a page refresh, go to salesforce Help & Training, and search for the solution:
 
How to use DHTML (Dynamic HTML) in an s-control in order to update fields without refreshing?
 
 
ben_hizakben_hizak
Thanks,
That works. one problem however: the date used is of the user's machine so, I just tried turning my date to 2010 and changing it. and it stamps it as 2010. so I'd like to use a system time variable.

I've tried
temporal.Audited_date__c= new Date({!TODAY()});

This gave me the 01/01/1970 time stamp.

Any idea why?

By the way, regarding the 2nd question, I found that it isn't such an issue, since custom buttons disappear as soon an inline edit is made. they thought of it....

Thanks again.
CaptainObviousCaptainObvious
I see..
 
Add the quotes and you should get the correct date: temporal.Audited_date__c = new Date('{!TODAY()}');
 
Any time javascript does not recognize a variable as a date, it'll return 1/1/1970 :D
ben_hizakben_hizak
I've put in the single quotes as follows, that still gives the user's machine's date. how can I put the server's date?

Code:
temporal.Audited_date__c= new Date('{!TODAY()}');