I created this script to auto log calls based on the current disposition field...it also handles creation of follow up tasks. Basically elminates the need for the standars call log process. I have it working on the Account SO but cannot get it working on the leads SO.... not sure what the deal is. Here is a copy of the script for the leads object:
{!requireScript("/soap/ajax/13.0/connection.js")}
try
{
var account = new sforce.SObject("Lead");
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 = "{!Lead.OwnerId}";
task.Subject = "{!Lead.Current_Disposition__c}";
task.WhatId = "{!Lead.Id}";
task.Description = "{!Lead.Notes__c}";
// set status to closed
task.Priority = "Normal";
task.Status = "Completed";
// if follow up required, then create the follow up task
if ({!Lead.Follow_Up_Required__c})
{
followUp.OwnerId = "{!Lead.OwnerId}";
followUp.Subject = "{!Lead.Current_Disposition__c}";
followUp.WhatId = "{!Lead.Id}";
followUp.Description = "{!Lead.Notes__c}";
// set status to closed
followUp.Priority = "Normal";
followUp.Status = "Not Started";
followUp.IsReminderSet = true;
followUp.ActivityDate = Date.valueOf({!Lead.Follow_Up_Date__c});
}
var result = sforce.connection.update([lead]);
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"))
{
{!Lead.IsDirty__c} = false;
{!Lead.Follow_Up_Required__c} = false;
{!Lead.Follow_Up_Date__c} = null;
{!Lead.Current_Disposition__c} = null;
{!Lead.Notes__c} = null;
result = sforce.connection.update([lead]);
if (result[0].getBoolean("success"))
{
window.location.reload();
}
}
else
{
alert("Error!");
}
}// End try block
catch(err)
{
alert("Error creating task: " + err.toString());
}
I am receiving a "missing ) after arguments list" error, not sure why...code is identical except for field names and variables.
Here is copy of working code on account object:
{!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";
// if follow up required, then create the follow up task
if ({!Account.Follow_Up_Required__c})
{
followUp.OwnerId = "{!Account.OwnerId}";
followUp.Subject = "{!Account.Current_Disposition__c}";
followUp.WhatId = "{!Account.Id}";
followUp.Description = "{!Account.Notes__c}";
// set status to closed
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());
}
note with the lead script you are doing data binding using the {!Lead.xxx} but on the account you are not. Don't know if this is the problem but this is were the two scripts are different. Maybe take a look at and change the lead script to match that of the account script and see if that makes any difference.
Hi, well the error is pretty explicit, you are missing a ')'. Tough i did copy both codes and compare it and there's no ')' missing apparently.
Could you tell me which line is throwing the error?
Thanks.
Ignacio.
Ha I have no idea lol..its got me stumped
In compairing the two scripts I found one variation as seen here:
The lead script:
if (result[0].getBoolean("success") && resultT[0].getBoolean("success") && resultF[0].getBoolean("success"))
{
{!Lead.IsDirty__c} = false;
{!Lead.Follow_Up_Required__c} = false;
{!Lead.Follow_Up_Date__c} = null;
{!Lead.Current_Disposition__c} = null;
{!Lead.Notes__c} = null;
The account script:
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;
note with the lead script you are doing data binding using the {!Lead.xxx} but on the account you are not. Don't know if this is the problem but this is were the two scripts are different. Maybe take a look at and change the lead script to match that of the account script and see if that makes any difference.