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
SunilSunil 

How to store current date into custom date field at Opportunity Object

Hi,
 
I am trying to store current date into one of the custom date field at Opportunity object. I am using the code below: -
 
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<script type="text/javascript" src="/js/functions.js"></script> 
<script src="/soap/ajax/9.0/connection.js"></script> 
<script language="javascript"> 

function saveRec() 
{ 
var opp = new sforce.SObject("Opportunity"); 
opp.set("Id", "{!Opportunity.Id}"); 

var mydate=new Date() 
var year=mydate.getYear() 
if (year < 1000) 
year+=1900 
var day=mydate.getDay() 
var month=mydate.getMonth()+1 
if (month<10) 
month="0"+month 
var daym=mydate.getDate() 
if (daym<10) 
daym="0"+daym 

var date1=month+"/"+daym+"/"+year; // this returns eg. 05/09/2007

opp.set("Questionnaire_Back__c",date1); 

 
I am getting error "05/09/2007' is not a valid for the type 'xsd:date'. Any idea where I am doing mistake? Do you have any example of updating date field?
 
Thanks in advance.
 
cheenathcheenath
Check out the Ajax CRUD > create with other data types example here.

You can assign a javascript Date to the field and the toolkit will convert it to
the correct xml string.

HTHs,



 
jeremy_wjeremy_w
I've done this and a format that worked was "YYYY-MM-DD" constructed the same way as you were (from javascript date methods).