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

Getting Date from Today()
Hi,
Good Day!
How should i assign today date to 'Actual_start_date__c', When Start Project(Custom button) is clicked. The javascript code for the custom button is given below.
Thanks in advance,
Durairaj
Good Day!
How should i assign today date to 'Actual_start_date__c', When Start Project(Custom button) is clicked. The javascript code for the custom button is given below.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} // identify the record var o = new sforce.SObject("Project__c"); o.id = "{!Project__c.Id}"; // Update the Record Type o.RecordTypeId = '01210000000FCJwAAO'; o.Status__c = 'Active'; o.Actual_start_date__c = {!TODAY()}; // save the change //sforce.connection.update(o); var result = sforce.connection.update([o]); //refresh the page //window.location.reload(); if( result[0].success === "true" ) { window.location.reload(); } else { alert( result[0].errors.message ); }
Thanks in advance,
Durairaj
The problem with the code is that you are not using the xsd format that must be specified while using javascript and that's the reason you are able to see this error.
Please do follow the code provided below and now you will surely be able to assign date to your custom field.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
// identify the record
var o = new sforce.SObject("Project__c");
o.id = "{!Project__c.Id}";
// Update the Record Type
o.RecordTypeId = '01210000000FCJwAAO';
o.Status__c = 'Active';
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd = '0'+dd
}
if(mm<10) {
mm = '0'+mm
}
today = yyyy + '-' + mm+ '-' +dd;
o.Actual_start_date__c =today;
// save the change
//sforce.connection.update(o);
var result = sforce.connection.update([o]);
//refresh the page
//window.location.reload();
if( result[0].success === "true" ) {
window.location.reload();
}
else {
alert( result[0].errors.message );
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
All Answers
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd = '0'+dd
}
if(mm<10) {
mm = '0'+mm
}
today = mm + '/' + dd + '/' + yyyy;
document.write(today);
The problem with the code is that you are not using the xsd format that must be specified while using javascript and that's the reason you are able to see this error.
Please do follow the code provided below and now you will surely be able to assign date to your custom field.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
// identify the record
var o = new sforce.SObject("Project__c");
o.id = "{!Project__c.Id}";
// Update the Record Type
o.RecordTypeId = '01210000000FCJwAAO';
o.Status__c = 'Active';
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd = '0'+dd
}
if(mm<10) {
mm = '0'+mm
}
today = yyyy + '-' + mm+ '-' +dd;
o.Actual_start_date__c =today;
// save the change
//sforce.connection.update(o);
var result = sforce.connection.update([o]);
//refresh the page
//window.location.reload();
if( result[0].success === "true" ) {
window.location.reload();
}
else {
alert( result[0].errors.message );
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
Even after trying your code, I am getting the same error as i mentioned in the previous screenshot
Thanks