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
Shannon Andreas 21Shannon Andreas 21 

Javascript button Help - Keeps returning me to Home tab on Save

Hello!

Need help with this button. Keeps returning me to the Home tab. How can I make it return to the case where the button began?

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

var tskObj = new sforce.SObject("Task");
tskObj.Status = "Not Started"; 
tskObj.RecordTypeId ="012Q0000000DIKh"; 
tskObj.OwnerId ="{!$User.Id}"; 
tskObj.WhoId ="{!Case.ContactId}";
tskObj.WhatId="{!Case.Id}";
tskObj.Priority ="Normal"; 
tskObj.Subject ="VOC VEP Follow Up Request"; 

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

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

Thank you!!

Shannon
Amit Singh 1Amit Singh 1
Hi Shannon,

Try below JavaScript Code.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 

var tskObj = new sforce.SObject("Task");
tskObj.Status = "Not Started"; 
tskObj.RecordTypeId ="012Q0000000DIKh"; 
tskObj.OwnerId ="{!$User.Id}"; 
tskObj.WhoId ="{!Case.ContactId}";
tskObj.WhatId="{!Case.Id}";
tskObj.Priority ="Normal"; 
tskObj.Subject ="VOC VEP Follow Up Request"; 

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

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

Let me know what is the outcome.

Thanks,
AMit Singh.