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
JillWJillW 

Creating a Custom Task Button in Opportunities

I want to create a button on the opportunity page that creates a special kind of task "Request Contract". I want it to assign the task to a particular individual and link it to the opportunity. So far, I've been able to create the task and assign it to a particular person.

 

However, I can't figure out how to link it to the opportunity. Or rather, I can't figure out how to pass the opportunity's ID to the task. Everything I've tried just results in an error message. Even when I insert the opportunity ID from the "insert merge field" drop down box, the button doesn't work.

 

Can somebody help with this?

 

Thanks in advance.

 

J.

 

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

var t1= new sforce.SObject("Task" );
t1.OwnerId = "00530000001itnL";//SFDC ID of user record
t1.Subject = "Requesting Contract";
t1.Status = "Not Started";
t1.Priority = "Normal";
t1.What = {!Opportunity.Id}

result = sforce.connection.create([t1]);

WYamWYam

Hey J,

 

Bit late but I hope that my shot in the dark works out. 

 

Try using t1.WhatId={!Opportunity.Id}  instead of t1.What={!Opportunity.Id}

 

I hope this helps.

 

 

Cheers,

Will

Message Edited by WYam on 03-01-2010 01:20 PM
Message Edited by WYam on 03-01-2010 01:20 PM
JillWJillW

Yes! That works! :smileyvery-happy:

 

I'm still having problems, though. For one thing, it creates the task but doesn't open it. This means I have to give it a due date.

 

Which brings me to the next problem. I can hard code a due date in (t1.ActivityDate = "03/03/2010"), but I can't dynamically enter a date. I've tried "t1.ActivityDate = TODAY();" , but I just get an error message "object expected."

 

Any ideas on how to either opening the task automatically or assigning a due date?

 

Thanks for your help!

WYamWYam

I'm glad we got past problem 1 ;)

 

Again, shot in the dark. To create the task as open, try t1.ISCLOSED = "FALSE"

 

I'm hoping by "This means I have to give it a due date" you mean that my above suggestion works because the date one is stumping me for now. Let me know!