• kelsey.joyce1.394641015380688E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I am trying to get a Javascript button to work - it is working when it comes up updating the lead fields however the task is not being created and the page is not being reloaded.  Any ideas where I am going wrong?

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}

var lead = new sforce.SObject('Lead');
lead.id ='{!Lead.Id}';
lead.strike__c = '1';
lead.status = 'Contact Not Made'
lead.Lead_Status_Details__c = 'Called LM & Emailed'

try{
var result = sforce.connection.update([lead]);

var task = new sforce.SObject('Task');
task.RecordTypeId = '012D0000000B9be';
task.OwnerId = '{!User.Id}';
task.Subject = 'No Connect';
task.Description = 'Left Message and Sent Email';
task.WhatId = '{!Lead.Id}';
task.Type = 'No Connect';
task.ActivityDate = new Date();
task.Status = 'Completed';

var resultTask = sforce.connection.create([task]);

if(resultTask[0].success=='true' && resultLead[0].success=='true'){
alert('The Lead has been Updated Successfully and the Task was Created.');
location.reload();
}
}
catch(e){
alert('An Error has Occured. Error: ' + e);
}
I am trying to get a Javascript button to work - it is working when it comes up updating the lead fields however the task is not being created and the page is not being reloaded.  Any ideas where I am going wrong?

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}

var lead = new sforce.SObject('Lead');
lead.id ='{!Lead.Id}';
lead.strike__c = '1';
lead.status = 'Contact Not Made'
lead.Lead_Status_Details__c = 'Called LM & Emailed'

try{
var result = sforce.connection.update([lead]);

var task = new sforce.SObject('Task');
task.RecordTypeId = '012D0000000B9be';
task.OwnerId = '{!User.Id}';
task.Subject = 'No Connect';
task.Description = 'Left Message and Sent Email';
task.WhatId = '{!Lead.Id}';
task.Type = 'No Connect';
task.ActivityDate = new Date();
task.Status = 'Completed';

var resultTask = sforce.connection.create([task]);

if(resultTask[0].success=='true' && resultLead[0].success=='true'){
alert('The Lead has been Updated Successfully and the Task was Created.');
location.reload();
}
}
catch(e){
alert('An Error has Occured. Error: ' + e);
}