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
Rob PetrieRob Petrie 

Custom Task Button almost perfect... need to take it to the finish line

Context: Based on the way our sales reps need to view activity data (with respect to how our parent and child accounts are related), we had to create custom buttons for logging calls. After developing these buttons, they are exactly what our sales reps need and actually have been improved to be a substantial time saver, even with the final lingering error I can't seem to code around. 

Below is the code I have for a Custom Call button. We have multiple buttons for different activity types, but they all follow this pattern. The issue: When our AEs click save, it takes them to their home page as opposed to taking them back to the contact record that they logged the call on. Most of them use multiple tabs, and as stated these custom buttons save us time and map our activity in the unique way we need it to, but it would be awesome to figure out the issues in the last part of my code (In bold) to get them back to the contact or account that they logged the activity at when they click save. Any help is GREATLY appreciated!

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

var taskObj = new sforce.SObject("Task"); 
taskObj.RECORDTYPEID = '012a0000001WDSk'; 
taskObj.Type = 'Cold Call';
taskObj.WhoId = '{!NULLVALUE(Contact.Id,Lead.Id)}';
taskObj.WhatId = '{!NULLVALUE(Account.ParentId, Account.Id)}';
taskObj.Status = 'Completed';

var year = '{!TEXT(YEAR(TODAY()))}';
var month = '{!IF(LEN(TEXT(MONTH(TODAY())))==1,"0"&TEXT(MONTH(TODAY())),TEXT(MONTH(TODAY())))}';
var day = '{!IF(LEN(TEXT(DAY(TODAY())))==1,"0"&TEXT(DAY(TODAY())),TEXT(DAY(TODAY())))}';
taskObj.ActivityDate = year.concat("-",month,"-",day);
taskObj.Completion_Date__c = year.concat("-",month,"-",day);


var result = sforce.connection.create([taskObj]); 

if (result[0].success=='false') { 
alert(result[0].errors.message); 
} else { 
var newURL = '/' + result[0].id + '/e'; 
window.top.location = newURL; 
}

 
Rob PetrieRob Petrie
Anyone?