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
DPhilDPhil 

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:

==========

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

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
Hi,

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

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

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

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

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

for more information check the below link.
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008qphIAA
DPhilDPhil
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.
Thanks.