+ Start a Discussion
megmooPDXmegmooPDX 

setting Related To object in javascript in button to open new task

I have a custom button on my activity related list of a custom object named member. I'm converting it from using the URL hack method to the javascript method. That button executes the following javascript when clicked:

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

var taskObj = new sforce.SObject("Task");
taskObj.Subject ='Received DNE call';
tskObject.tsk3 = 'Member'

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

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

Without the line
tskObject.tsk3 = 'Member'
in the code, this works great. However, I need to set the Related To object to my custom object Member, otherwise it defaults to Opportunity. Using the URL hacking method to open a new task, I can pass the object reference via the tsk3_mlktp=a07 (with a07 being the ID of my custom Member object), but that doesn't work in the javascript method. 

I've tried the following lines of code, all of which give me an error of tskObject is not defined
tskObject.What = 'Member'
tskObject.What = 'a07'
tskObject.tsk3_mlktp = 'Member'
tskObject.tsk3_mlktp = 'a07'
tskObject.tsk3 = 'Member'
tskObject.tsk3 = 'a07'
 

Any ideas out there on how to pass the object ID/name to get the Related To drop-down to default to the correct object?
Best Answer chosen by megmooPDX
megmooPDXmegmooPDX
I have found that using Publisher Actions is a better solution than URL hacking or a javaScript button. Publisher Actions have their limits (see my Idea (https://success.salesforce.com/ideaView?id=08730000000l2BJAAY) on the Idea Exchange for an enhancment), but so far, they're much better.