You need to sign in to do that
Don't have an account?
Save time on the click of Custom Button
I have a custom button added to case detail layout. i have also created Last_RequestUpdate__c(is a date/time field) on case object.
My question: when the user clicks on the custom button, date/time field should capture the last time the Custom button was clicked.
My try: i have a javascript writtin on custom button/link .
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}
var caseId = '{!Case.Id}';
var resultSet = sforce.connection.query("SELECT Last_RequestUpdate__c FROM Case WHERE Id = '" + caseId + "'");
var caseObj = resultSet.records;
caseObj.Last_RequestUpdate__c = "{!NOW()}";
alert(caseObj.Last_Update_Requested__c);
var result = sforce.connection.update([caseObj]);
My Problem is: alert(caseObj.Last_Update_Requested__c); shows me datetime "10/18/2013 4:09 AM"
then i am getting this error: {faultcode:'soapenv:Client', faultstring:''10/18/2013 4:09 AM' is not a valid value for the type xsd:dateTime', }
Could you please help me how to store the value in Last_RequestUpdate__c field?
Hello,
Now() is not a JavaScripts method, get current date and time in JS as follows:
var currentdate =newDate();var datetime ="Last Sync: "+ currentdate.getDate()+"/"+(currentdate.getMonth()+1)+"/"+ currentdate.getFullYear()+" @ "+ currentdate.getHours()+":"+ currentdate.getMinutes()+":"+ currentdate.getSeconds();
or
var newDate = new Date();
var datetime = newDate.today() + ":" + newDate.timeNow();
Hi,
Thanks for ur reply. i tried to use ur first option.
got date time value. but Last_RequestUpdate__c field is getting updated.
still throwing the same error.
var newDate = new Date();
var datetime = new Date.today() + ":" + new Date.timeNow();
var caseId = '{!Case.Id}';
var resultSet = sforce.connection.query("SELECT Last_Update_Requested__c FROM Case WHERE Id = '" + caseId + "'");
var caseObj = resultSet.records;
caseObj.Last_Update_Requested__c = datetime;
alert('datetime===>' + datetime );
var result = sforce.connection.update([caseObj]);
Any idea why updation is not happening?
i used
var currentdate =newDate();var datetime ="Last Sync: "+ currentdate.getDate()+"/"+(currentdate.getMonth()+
1)+"/"+ currentdate.getFullYear()+" @ "+ currentdate.getHours()+":"+ currentdate.getMinutes()+":"+ currentdate.getSeconds();
still got the same errror
Hello,
Remove ":" and try:
var newDate = new Date();
var datetime = new Date.today() + ' ' + new Date.timeNow();
else try:
var now =newDate();var datetime = now.getFullYear()+'/'+(now.getMonth()+1)+'/'+now.getDay();
datetime +=' '+now.getHours()+':'+now.getMinutes()+':'+now.getSeconds();
Hi,
Pls try this : should work as expected.
---------------------------------------------------
{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")}
var caseId = '{!Case.Id}';
var resultSet = sforce.connection.query("SELECT id, Last_RequestUpdate__c,Subject FROM Case WHERE Id = '" + caseId + "'");
records = resultSet.getArray("records");
var caseobj= records[0];
var d =new Date();
var n=d.toJSON();
caseobj.Last_RequestUpdate__c = n;
var result = sforce.connection.update([caseobj]);
Hi JK,
Thanks.
I didnt get any error this time.
but, Last_RequestUpdate__c field didnt get updated on case.
Could you tell me why so? Thanks
I guess...you might have to refresh the page to see the update after the button is clicked.
I was able to see the same code update the field in my developer login...but had to refresh the page ...as the button is not having any action after update.
Thanks
JK
Come across the same need, were you be able to fix it at all?