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

How do I store a date field in onClick Javascrpt function for a Custom button
Hi All,
Below is my script used for a custom button. I am unable to store the date and get error like below:
faultstring:''0.0001823305154980938' is not a valid value for the type xsd:date',
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} var connection = sforce.connection; var ex = new sforce.SObject("CustomF1__c"); ex.DateF1__c = {!DATEVALUE(TEXT(CustomF2__c.DateF2__c))}; ex.Name = "{!CustomF2__c.Name}"; var rs = connection.create([ex]); if (rs[0].success=='false') alert("Message"+rs[0].errors.message);
CustomF2__c is the object where I am creating this button and CustomF1 is the object which I want to create when user hits this button.
Please help me on this. Thanks in advance!
Regards,
Lakshman
Hi Lakshman,
Try the following :-
Hope this helps.
Hi Lakshman,
You should first check the value that is being passed using an alart box.
Apparently, ajax toolkit uses API calls in the form of SOAP messages to update data. As per the API docs, salesforce accepts date values in the following format "YYYY-MM-DDThh:mm:ssZ"
Add the following function to format the date value as per Salesforce:
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;
}
You can then use the value as follows:
ex.DateF1__c = fixDate(new Date("{!CustomF2__c.DateF2__c}"));
Let me know if that helps and mark it as a solution so that others get benefitted :)
Regards,
Sankalp
forcesecrets.blogspot.com
I resolved this by querying my date field for that particular record and assigned it to the destination date field record.
I did like below:
BTW in your apporach adding a function in onClick Javascript button, will give an error!!!
Regards,
Lakshman