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
Rony57Rony57 

Custom OnClick JavaScript Button to Update Status

I'm trying to create a custom OnClick JavaScript button that will update a Status field on my detail page  from Pending to Available when clicked on button. Here is my follwing code:-

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var pro = new sforce.SObject('APPa__Tickets__c'); 
pro.Id = '{!APPA__Tickets__c.Id}'; 
pro.APPA__Status__c = 'Available'; 
var result = sforce.connection.update([pro]); 
if(result[0].success=='true'){ 
alert('The Status Updated Successfully'); 
else{ 
alert('The Status Updated Unsuccessfully'); 

window.location.reload(true);}

But when i click on the button it shows an error:Unexpected Token else.  Help me out ..
Best Answer chosen by Rony57
Dushyant SonwarDushyant Sonwar
Check that the profile is ApI Enabled Option Is Checked or Not in Administrative Permissions Section in profile Detail Page

All Answers

Dushyant SonwarDushyant Sonwar
Hi Anurag ,
There is  one '}' missing in  your script

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var pro = new sforce.SObject('APPa__Tickets__c'); 
pro.Id = '{!APPA__Tickets__c.Id}'; 
pro.APPA__Status__c = 'Available'; 
var result = sforce.connection.update([pro]); 
if(result[0].success=='true'){ 
alert('The Status Updated Successfully'); 
}
else{ 
alert('The Status Updated Unsuccessfully'); 

window.location.reload(true);}
 
Rony57Rony57
@dushyant  Thanx for your quick reply, Now i am geeting this error"-


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

{faultcode:'sf:API_CURRENTLY_DISABLED', faultstring:'API_CURRENTLY_DISABLED: API is disabled for this User', detail:{UnexpectedErrorFault:{exceptionCode:'API_CURRENTLY_DISABLED', exceptionMessage:'API is disabled for this User', }, }, }
 
Dushyant SonwarDushyant Sonwar
Check that the profile is ApI Enabled Option Is Checked or Not in Administrative Permissions Section in profile Detail Page
This was selected as the best answer
Rony57Rony57
@dushyant thanx a  lot it worked.. :) :)