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
DeLiDeLi 

OnClick Javascript custom button creating Tasks

On a custom object, I have created a simple javascript button which creates tasks on the click.

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

var t = new sforce.SObject("Task");

t.OwnerId = '{!Custome_Object.User_Id}';
t.Subject = "Task With Jscript";
...
t.What = '{!Custome_Object.Id}'; 

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

if(result[0].getBoolean("success")){
window.location = "/" + result[0].id;
}else{
alert('Could not create record '+result);
}

I can't figure out how to set the t.What (Related To) field. I get the following error:

{errors:{message:'The external foreign key reference does not reference a valid entity: What', statusCode:'INVALID_FIELD', }, id:null, success:'false', }

My searches tuned out nothing. :(
Any suggestion would be appreciated.

btw, I don't want to use the URL hack or the URLFOR function.

Thank you
Best Answer chosen by DeLi
Phillip SouthernPhillip Southern
Hi, I think this might be duplicate question from the Answers board?  If so, I actually just answered there.....it should be WhatId as the parameter.

All Answers

Phillip SouthernPhillip Southern
Hi, I think this might be duplicate question from the Answers board?  If so, I actually just answered there.....it should be WhatId as the parameter.
This was selected as the best answer
DeLiDeLi
Thanks a bunch Phillip.

I tried "what_id" and didn't work, then used the "insert field" dropdown and it insterted {!Task.What}. Never thought to use WhatId.

Thank you again