You need to sign in to do that
Don't have an account?
Dominic Sharpe
OnClick Javascript Button for Tasks
I'm a beginner when it comes to Javascript. We have an existing custom button that creates a new task on the Contact object. Here's the existing code:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var myTask = new sforce.SObject("Task");
myTask.WhoId = "{!Contact.Id}";
myTask.Subject = "Follow Up";
sforce.connection.create([myTask]);
window.location.reload();
However, our requirements have changed. We now need the button to work ONLY when all tasks on the Contact are CLOSED. And instead of creating the task right away, the button should take the user to the task edit page to be able to enter comments. The user will save the task manually.
How do I use javascript to make sure that all tasks are closed?
How do I redirect the user to the task edit page?
Any tips and/or sample code I could work with would be of great help
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var myTask = new sforce.SObject("Task");
myTask.WhoId = "{!Contact.Id}";
myTask.Subject = "Follow Up";
sforce.connection.create([myTask]);
window.location.reload();
However, our requirements have changed. We now need the button to work ONLY when all tasks on the Contact are CLOSED. And instead of creating the task right away, the button should take the user to the task edit page to be able to enter comments. The user will save the task manually.
How do I use javascript to make sure that all tasks are closed?
How do I redirect the user to the task edit page?
Any tips and/or sample code I could work with would be of great help
I think you've reached the point where you'd be better off using a custom button that routes to a Visualforce page. That page could check the status of existing tasks in it's init method quite easily, and then could either display an error message and list of tasks if some are open, or redirect to the edit page by returning a page reference with the standard URL.
The page controller would look roughly like this:
Then you just need to implement a page that uses this extension controller: