1

I created a JS button that creates an Opportunity and it populates certain fields with data from another Object (custom object called Deals). All the fields are working as they should except for CloseDate. The Opportunity CloseDate is of type Date and the CloseDate in Deal is of type Date as well.

However when I run:
newOpportunity.CloseDate = {!Deal_Registration__c.Close_Date__c};

It returns an error saying the format is wrong.(data shown below)

When I run

var curDate = new Date({!Deal_Registration__c.Close_Date__c});
newOpportunity.CloseDate = curDate;

It returns the wrong date. The Values I get back are:

When Deal CloseDate is equal to 03/04/2014

JS returns CloseDate in an alert() with 0.0003723932472691162

and curDate returns Wed Dec 31 1969 19:00:00 GMT-0500 (EST)

Any help would be greatly appreciated, I tried to follow the answer to Date coming back in wrong format using JS remoting. but as shown above I get the wrong date returned

1

It looks like your JavaScript is interpreting your date as an equation; 3 divided by 4 divided by 2014 is 0.000372....

I think you need to add quotes to your statement. Instead of

var curDate = new Date({!Deal_Registration__c.Close_Date__c});

try

var curDate = new Date('{!Deal_Registration__c.Close_Date__c}');

That should cause the emitted script to be a string and interpreted correctly.

  • Hah, worked like a charm... thanks a lot for the solution Mike – jnoel10 Apr 25 '14 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.