You need to sign in to do that
Don't have an account?

OnClick Timestamp Javascript Custom Button
Hi guys!
I checked out a certain JAVA fix and noticed that it may just be the solution to this brickwall I ran into. I have the following custom button OnClick Javascript code on a sample object that should imprint both Date and Time values on a DateTime field. I did use the new Date() syntax but it only works for Date fields and not DateTime. I was wondering, how this post would fit into what I've formulated. Thanks in advance!
Mine:
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var v=new sforce.SObject("Opportunity");
v.JavaDateButtonTest__c="{!Opportunity.JavaDateButtonTest__c}";
v.id = "{!Opportunity.Id}";
if((v.JavaDateButtonTest__c==''))
{
var date = new Date('{!TODAY()}');
v.JavaDateButtonTest__c=date;
result=sforce.connection.update([v]);
}
-----------------------------------------------------------
Fix:
function fixTime(time){ if(time < 10) {time = "0" + time}; return time; } function fixDate(date){ var Month = fixTime(date.getMonth() + 1); var Day = fixTime(date.getDate()); var UTC = date.toUTCString(); var Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6); var Minutes = fixTime(date.getMinutes()); var Seconds = fixTime(date.getSeconds()); return date.getFullYear() + "-" + Month + "-" + Day + "T" + Time; }
-----------------------------
I also got this from another site and I'm not sure if this is usable for what I cited above:
/** * Set Javascript Date Time to Salesforce Date Time; * @param dateTimeObj - date time string * @return salesforce date time object **/ function setStringToDateTime(dateTimeObj){ var dateTimeObj; if (dateTimeObj != null) { dateTimeObj = sforce.internal.stringToDateTime(dateTimeObj); } return dateTimeObj; }
Sorry bout the spam, got it fixed through this and don't mind the Opportunity Object, I was just experimenting with that one.
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var v=new sforce.SObject("Opportunity");
v.JavaDateButtonTest__c="{!Opportunity.JavaDateButtonTest__c}";
v.id = "{!Opportunity.Id}";
alert(v.JavaDateButtonTest__c);
if((v.JavaDateButtonTest__c==''))
{
var d =new Date();
var n=d.toJSON();
v.JavaDateButtonTest__c=n;
result=sforce.connection.update([v]);
}
location.reload(true);
navigateToUrl('https://na1.salesforce.com//secur/logout.jsp');