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
CW83CW83 

javascript button update field

I have a javascript button I am trying to create to update a picklist field on a custom object.  Here is the code for the button:

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

var p = new sforce.SObject('Projects__c');
p.id = "{Projects__c.Id}";
p.Status__c = "Closed";
result = sforce.connection.update([p]);
location.reload(true);

The code is not throwing errors on the object it is just not updating the field.  The page is reloading. Anything wrong with the code?

Best Answer chosen by CW83
logontokartiklogontokartik
Looks like you missed "!" in your merge field it must be {!Projects__c.Id}. Also you can alert on result.message if you want to see any errors.

All Answers

logontokartiklogontokartik
Looks like you missed "!" in your merge field it must be {!Projects__c.Id}. Also you can alert on result.message if you want to see any errors.
This was selected as the best answer
CW83CW83
Thank you so much.  I don't know how I missed that.
Michaela ChrysostomouMichaela Chrysostomou
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 


var p = new sforce.SObject("Live_Events__c"); 
p.StatusB__c= "Deleted"; 
result = sforce.connection.update([p]); 
location.reload(true);


What I missed?
Is not working
Lightening AdarshLightening Adarsh
Hi Michaela Chrysostomou,
Please Use This.
You have missed assigning the ID to variable

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var p = new sforce.SObject("Live_Events__c"); 
p.id = "{!Live_Events__c.id}";
p.StatusB__c= "Deleted"; 
result = sforce.connection.update([p]); 
location.reload(true);


!Hope This will work..:)