+ Start a Discussion
BabluBablu 

populate current date when we click on [Accept] custom button on case

Hi,

I want to populate current date and time in custom field (case accepted date) when i click on [Accept] custom button on case

Existing code on [Accept] button which updates the ownership, now i want to include the code to update case accepted date also. can you help on this

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.OwnerId = '{!$User.Id}';
var result = sforce.connection.update([caseObj]);

if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}

 Thanks,
Bablu
Vinoth Vijaya BaskerVinoth Vijaya Basker
Hi, 

I have updated your code. Please find the below code, 
 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.OwnerId = '{!$User.Id}';
caseObj.Case_Accepted_Date__c = new Date().toISOString();
var result = sforce.connection.update([caseObj]);

if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}


Thanks,
Vinoth
BabluBablu
Hi , 

Thanks for your help Vinoth. small issue in the format : 2015-10-19T15:47:04.604+05.5:30

i want 2015-10-19 only . could you please look at this ?

Thanks,
Bablu
BabluBablu
Custom field (Case accepted0 is a text field
Vinoth Vijaya BaskerVinoth Vijaya Basker
Hi, 

I have updated the code for the format you required, 

Please find the below updated code, 

Updated line is given below,
caseObj.Accepted_Date__c = (new Date().toISOString()).substring(0,10);
 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.OwnerId = '{!$User.Id}';
var currentDate	 = 
caseObj.Accepted_Date__c = (new Date().toISOString()).substring(0,10);

var result = sforce.connection.update([caseObj]);

if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}

Thanks,
Vinoth
BabluBablu
Hi Vinoth,

Still the same issue. how to remove  T16:27:27.485+05.5:30 from the below date

Accepted Date : 2015-10-19T16:27:27.485+05.5:30
Vinoth Vijaya BaskerVinoth Vijaya Basker
Hi, 

I have created the text field Accepted Date and tested the above code. The output is: 2015-10-19 is Populated in the text field. 

caseObj.Accepted_Date__c = (new Date().toISOString()).substring(0,10);

The abvoe line of code removes the "T16:27:27.485+05.5:30" part and only popualtes 2015-10-19. 


Thanks,
Vinoth
BabluBablu

Hi, are you usingh the Text field only or Date/Time field ? 
Accepted_Date__c ?


Can you see the below screen , still it displys the incorrect format 

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.OwnerId = '{!$User.Id}';
var currentDate =
caseObj.Case_Accepted__c = (new Date().toISOString()).substring(0,10);
var result = sforce.connection.update([caseObj]);
if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}

User-added image
Vinoth Vijaya BaskerVinoth Vijaya Basker
I am using Text field. 
BabluBablu
ok, do you have any idea why it is not working for me ?