+ Start a Discussion

Date error when creating record from a custom button

I'm using a custom button to create a new record in a custom object, but the code is failing when I try to insert a date during the process.

I have created a custom object called "Project" with an api name of "Production__c".

I have added a custom button to the Opportunity page to create a new Project record and pre-populate it with some fields from the Opportunity. 

I'm trying to copy a custom date value from Opportunty to the Project record, but it fails with an error: "[faultcode:'soapenv:Client',
faultstring:"0.0022343594836146973' is not a valid value for the type xsd:date', }".

Here is the code:



var Proj = new sforce.SObject("Production__c");

Proj.Name = "{!Opportunity.Id}";
Proj.Account_Name__c = "{!Opportunity.AccountID}";
Proj.Opportunity_Name__c = "{!Opportunity.Name}";
Proj.Date_Signed__c = {!Opportunity.Date_Signed__c};

result = sforce.connection.create([Proj]);

if(result[0].success == 'true'){
    window.location = "/" + result[0].id + "/e";}
else {alert("Error creating Project");}


Any help would be appreciated! Thanks.
Anoop yadavAnoop yadav

Proj.Date_Signed__c = "{!Opportunity.Date_Signed__c}";

instead of
Proj.Date_Signed__c = {!Opportunity.Date_Signed__c};

and then try.
I tried it and got this error:

"fultstring:' '27/06/2014' is not a valid value for the type xsd:date'
Anoop yadavAnoop yadav

xmlNode.InnerText = tmpDate.ToUniversalTime().ToString("yyyy-MM-dd");

for more information check the below link.
Hi, thanks for your help. There are a couple of different methods in there.  Can you tell me exactly how I need to format up that line, I've tried a few things and keep getting errors.

So instead of:

Proj.Date_Signed__c = {!Opportunity.Date_Signed__c};

What should it be exaclty?

Sorry to be a bit dim, but I'm new to this.