+ Start a Discussion
gireeshzgireeshz 

problems with Custom Detail Page Button

Hello,

I am working on my first custom Detail page button and am having some problems.  I am trying to use the 'execute javascript' option using the 'onClick' event.  All I want this button to do is change the value in a field on the record.

The code that I am using is pasted below.  It is a modification of some code that I am successfully using in a custom button on a Search Page Layout.  When I try to run this, I get a Javascript error saying '<sforce id>' undefined, where <sforce id> is the record id for the record I am currently viewing.

I cannot seem to find ANY code examples of a custom detail page button  anywhere.  Can anyone help out?  I am VERY rusty with Javascript - is my problem a mere syntax/useage error??

Many thanks to the SF community!


Here is the code I am using:

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

var newRecords = [];
 
var c = new sforce.SObject("Session__c");
c.id ={!Session__c.Id};
c.Status__c = "Approved";
newRecords.push(c);

result = sforce.connection.update(newRecords);

window.location.reload();
TimflyTimfly

try changing update syntax to:

result = sforce.connection.update(newRecords[0]);

cheenathcheenath
c.id must be a string. So you have to put the merge field inside quotes.


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

var newRecords = [];
 
var c = new sforce.SObject("Session__c");
c.id ="{!Session__c.Id}";
c.Status__c = "Approved";
newRecords.push(c);

result = sforce.connection.update(newRecords);

window.location.reload();




gireeshzgireeshz
thanks for the suggestions - that fixed it!