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

Setting a date field through javascript

I am not sure what just happened there but here is my question..probably a very easy question but I am new to javascript. I have an scontrol written in javascript and I am getting the value from a date field this way:
var OpptyCloseDate = {!Opportunity_Renewal_Close_Date};
I am then trying to put this variable into a the Close Date of a newly created oppty...using this:
 newoppty.set("CloseDate", OpptyCloseDate);
What am I missing? I am getting an error. SUrely I need to do something with the dates I just have no idea what!

Message Edited by sgorema on 08-30-2006 12:19 PM

Hello Sgorema,

You just have to use the function Sforce.Util.ToIsoDate to format at salesforce style javascript date.



I tried the following:

var OpptyCloseDate = Sforce.Util.ToIsoDate({!Opportunity_Renewal_Close_Date});


But got an error - Object doesn't support this property or method.

Is the ToIsoDate function available to me through the ajax toolkit? Or do I need to include this function in my code?


I am new to all of this so excuse my questions!


You need to cast the variable you pass as a date (or datetime  as needed)


var OpptyCloseDate = Sforce.Util.ToIsoDate(new Date("{!Opportunity_Renewal_Close_Date}"));

or it the renewal close date is a datetime;

var OpptyCloseDate = Sforce.Util.ToIsoDateTime(new Date("{!Opportunity_Renewal_Close_Date}"));


hmm..I added that. I have the following:

var OpptyCloseDate = Sforce.Util.ToIsoDate(new Date("{!Opportunity_Renewal_Close_Date}"));

And am still getting the 'Object doesn't support this property or method' error.

new Date is working fine and I am returned 'Thu Aug 30 00:00:00 EDT 2007'.

It is erroring out on the ToIsoDate function.


Any ideas?



I just use/set a javascript date...

dateObj = new Date();

Then just update the field with dateObj.  I didn't know about the other function.


The following worked fine:

var OpptyCloseDate = new Date("{!Opportunity_Renewal_Close_Date}");

Without the ToIsoDate function.I was able to place OpptyCloseDate into the Close Date of the new function.

I am confused though...when do you need to use ToIsoDate?



It was not the Merge field to put in IsoDate but you Javascript Date!!!! ie your javascript variable but of course you have to validate it as a date first