You need to sign in to do that
Don't have an account?
DPhil
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.
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.
Use
Proj.Date_Signed__c = "{!Opportunity.Date_Signed__c}";
instead of
Proj.Date_Signed__c = {!Opportunity.Date_Signed__c};
and then try.
"fultstring:' '27/06/2014' is not a valid value for the type xsd:date'
Use:
xmlNode.InnerText = tmpDate.ToUniversalTime().ToString("yyyy-MM-dd");
for more information check the below link.
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008qphIAA
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.