You need to sign in to do that
Don't have an account?
Chris Fisher
String to Date Time Format?
Hi All,
I having some trouble taking 15 days off of a datetime field.
var day = prompt("Enter Callback day", "01");
var month = prompt("Enter Callback Month", "11");
var year = prompt("Enter Callback Year", "2015");
var time = prompt("Enter Callback Time", "09:00");
try
{
var taskToCreate = new sforce.SObject("Task");
var datetime = year+"-"+month+"-"+day+"T"+time+":00Z";
datetime - 15;
taskToCreate.OwnerId = "{!$User.Id}";
taskToCreate.WhoId = "{!Lead.Id}";
taskToCreate.Subject = "Call";
taskToCreate.ActivityDate = new Date();
taskToCreate.Priority = "Normal";
taskToCreate.Status = "Not Started";
taskToCreate.IsReminderSet = true;
taskToCreate.ReminderDateTime = mydatetime;
result = sforce.connection.create([taskToCreate]);
if(result[0].success == "true")
{
location.reload();
}
else
{
alert(
"An Error has Occurred. Error: \r\n" +
result[0].errors.message
);
}
}
catch(e)
{
alert(
"An Un-expected Error has Occurred. Error: \r\n" +
e
);
}
Basically its a customer button that will create a task, that will link to a lead, but we want the tast to pop up 15 days before the date entered.
I think the problem is because "datetime" is a string and not a date time field. But how do i get it to be recognised as a datetime?
Thanks
I having some trouble taking 15 days off of a datetime field.
var day = prompt("Enter Callback day", "01");
var month = prompt("Enter Callback Month", "11");
var year = prompt("Enter Callback Year", "2015");
var time = prompt("Enter Callback Time", "09:00");
try
{
var taskToCreate = new sforce.SObject("Task");
var datetime = year+"-"+month+"-"+day+"T"+time+":00Z";
datetime - 15;
taskToCreate.OwnerId = "{!$User.Id}";
taskToCreate.WhoId = "{!Lead.Id}";
taskToCreate.Subject = "Call";
taskToCreate.ActivityDate = new Date();
taskToCreate.Priority = "Normal";
taskToCreate.Status = "Not Started";
taskToCreate.IsReminderSet = true;
taskToCreate.ReminderDateTime = mydatetime;
result = sforce.connection.create([taskToCreate]);
if(result[0].success == "true")
{
location.reload();
}
else
{
alert(
"An Error has Occurred. Error: \r\n" +
result[0].errors.message
);
}
}
catch(e)
{
alert(
"An Un-expected Error has Occurred. Error: \r\n" +
e
);
}
Basically its a customer button that will create a task, that will link to a lead, but we want the tast to pop up 15 days before the date entered.
I think the problem is because "datetime" is a string and not a date time field. But how do i get it to be recognised as a datetime?
Thanks
newInstance(year, month, day, hour, minute, second) Constructs a Datetime from Integer representations of the specified year, month (1=Jan), day, hour, minute, and second in the local time zone.
taskToCreate.ReminderDateTime = DateTime.newInstance(year,Month,Day,Hour,Minute,Second);
Could i also write as: newinstance(2016,01,01,09:00)
Nope on the second.
All 6 parameters are integer. From page 1927 of the Apex Developers Guide
var day = prompt("Enter Callback day", "01");
var month = prompt("Enter Callback Month", "11");
var year = prompt("Enter Callback Year", "2015");
var time = prompt("Enter Callback Time", "09:00");
var hour = time.substring(0,2);
var minute = time.substring(3,5);
var second = "00"
try
{
var taskToCreate = new sforce.SObject("Task");
var datetime = datetime.newinstance(year,month,day,hour,minute,second);
datetime - 15;
Which i think was smashingly, but error generated "Cannot Read Property 'newinstance' of undefined" I had Something similar early when i was using
var date = new date() This gives me the error "Date is not defined"
Is there something stopping dates being used on custom buttons?
Sorry - can't help much then.