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
PCRecyclerPCRecycler 

Custom Button for Checkbox Field

I'm trying to create a custom button on a custom object called Job that when used would mark a custom check box called Job_Item_Call_Out true.

 

Here is the code that i have:

 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var a = new sforce.SObject("Job");
a.Id = "{!Job__c.Id}";
a.{!Job__c.Job_Item_Call_Out__c} = true;
sforce.connection.update([a]);
location.reload(true);
When the button is executed i'm getting an error

 

A problem with the OnClick JavaScript for this button or link was encountered:

Unexpected number '.0'

Best Answer chosen by PCRecycler
Abrar Ul HaqAbrar Ul Haq

Please check the below code. It should work and will resolve the issue.

 

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

var myJob = new sforce.SObject("Job__c");
myJob.Id = "{!Job__c.Id}";
myJob.Job_Item_Call_Out__c = "true";
var result = sforce.connection.update([myJob]);
window.location.reload();

 

Object Name = Job__c

Field Name = Job_Item_Call_Out__c

 

Thanks & Best Regards.

All Answers

kiranmutturukiranmutturu

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
var a = new sforce.SObject("Job"); 
a.Id = "{!Job__c.Id}"; 
a.Job__c.Job_Item_Call_Out__c = true; 
sforce.connection.update([a]); 
location.reload(true);

 

 

remove the merge field syntax over there

Abrar Ul HaqAbrar Ul Haq

Please look at the below code for custom button javascript.

 

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

var myJob = new sforce.SObject("Job__c");

myJob.Id = "{!Job__c.Id}";
myJob.Job__c.Job_Item_Call_Out__c = "true";
var result = sforce.connection.update([myJob]);

 

It should resolve your problem. Please give me feedback if you have any query.

Thanks

PCRecyclerPCRecycler

 

This didn't work.  Got the following messgae "Can not set property  'Job_Item_Call_Out__c' of undefined.

 

any suggestions?

 

The object is Job__C and the field  is Job_Item_Call_Out__c and we are trying to set the value to true.

 

It seems very simple so i can't see why it wouldn't work.  This is being executed from a 

Execute JavaScriptOnClick JavaScript
Abrar Ul HaqAbrar Ul Haq

Please check the below code. It should work and will resolve the issue.

 

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

var myJob = new sforce.SObject("Job__c");
myJob.Id = "{!Job__c.Id}";
myJob.Job_Item_Call_Out__c = "true";
var result = sforce.connection.update([myJob]);
window.location.reload();

 

Object Name = Job__c

Field Name = Job_Item_Call_Out__c

 

Thanks & Best Regards.

This was selected as the best answer