function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jburns12jburns12 

Someone Please Help

I am trying to set the ActivityDate on a task via javascript executed by a button. I am able to set all other fields on the task, except for the date. Here is the code, I have been advised to use DueDate instead of ActivityDate, but that is contrary to the API documetation. I tried it anyway and it does not work. Niether attempt to update the ActivityDate is working. This is throwing off my reporting!

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

try
{
var account = new sforce.SObject("Account");
var task = new sforce.SObject("Task");
var followUp = new sforce.SObject("Task");

account.id = "{!Account.Id}";
account.IsDirty__c = true;

// set task 'assigned to' field to the current user
task.OwnerId = "{!Account.OwnerId}";
task.Subject = "{!Account.Current_Disposition__c}";
task.WhatId = "{!Account.Id}";
task.Description = "{!Account.Notes__c}";

// set status to closed
task.Priority = "Normal";
task.Status = "Completed";
task.ActivityDate=Date.valueOf({!Today()});

// if follow up required, then create the follow up task
if ({!Account.Follow_Up_Required__c})
{
followUp.OwnerId = "{!Account.OwnerId}";
followUp.Subject = "Follow Up Call";
followUp.WhatId = "{!Account.Id}";
followUp.Description = "{!Account.Notes__c}";

// set status to Open
followUp.Priority = "Normal";
followUp.Status = "Not Started";
followUp.IsReminderSet = true;
followUp.ActivityDate= Date.valueOf({!Account.Follow_Up_Date__c});
}

var result = sforce.connection.update([account]);
var resultT = sforce.connection.create([task]);
var resultF = resultT;

if (followUp != null)
{
resultF = sforce.connection.create([followUp]);
}

if (result[0].getBoolean("success") && resultT[0].getBoolean("success") && resultF[0].getBoolean("success"))
{
account.IsDirty__c = false;
account.Follow_Up_Required__c = false;
account.Follow_Up_Date__c = null;
account.Current_Disposition__c = null;
account.Notes__c = null;

result = sforce.connection.update([account]);

if (result[0].getBoolean("success"))
{
window.location.reload();
}
}
else
{
alert("Error!");
}
}// End try block
catch(err)
{
alert("Error creating task: " + err.toString());
}

 

 

 

SuperfellSuperfell

In what way is it not working ?

b-Forceb-Force

try to update this two line of code,

I just enclosed Merge fields in quotes

 

task.ActivityDate=Date.valueOf("{!Today()}");
followUp.ActivityDate= Date.valueOf("{!Account.Follow_Up_Date__c}");

 

Rest off all things are good

 

It may help you.

 

Thanks,

Bala

jburns12jburns12

No matter what i try the dates are still blank, this just doesnt make any sense. The quotations did not work either, ubt thank you very much for trying.

 

JB

b-Forceb-Force

please try this,

Create a some other custom field with same DataType and Try to set that,

by using toolkit I am able to set some custom DateTime Field

 

Thanks,

Bala