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
Paula Jarvis 4Paula Jarvis 4 

Edit Custom Button Java Script

I have a custom button that requies Users to provide reasons for closing an Account. I would like to omit two specific record types form this Java script so we can update the TYPE of Account. We currently are "stopped" from updating th TYPE field because of the Java scipt. Here is the script:

Account Custom Button or Link: Close Prospect ~ Salesforce - Enterprise Edition{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js") }


var leads = new Array();

leads[0] = new sforce.SObject("Account");
leads[0].id = "{!Account.Id}";

var _return = window.confirm('Are you sure you want to begin closing this Account?\nSelect Yes to start the closing process.');
if(_return)
{



var T = "{!Account.Type_Number__c}";
var curDate = new Date();



if(T == 1)
{
var curDate = new Date();
leads[0].RecordTypeId = "012500000009VUN";
}

else
{
alert("The 'Close Prospect' button is only for Prospect accounts. For Live accounts, please create an 'Archive' record at the bottom of the page and follow the archival steps. You can manually change the 'Type' of the account from Live to Archived.");
}



var result = sforce.connection.update(leads);


if (result[0].getBoolean("success"))
{
// Refresh window
window.location.reload();
}

else
{
alert("Request to close this account has failed. \n \nMake sure that you have filled the minimum information required to edit an Account. You can test this by editing a field and attempting to save the account record. \n\n If you can edit and save the account but still see this error, please contact your Salesforce Administrator.\n\nError code 'Acct_Close_1'");
}


}
James LoghryJames Loghry
Sounds like you just need to add logic to prevent the logic from executing.  For example, you could update the first if statement to the following:
 
if(_return && "{!Account.RecordTypeId} !== "ID1 GOES HERE" && "{!Account.RecordTypeId}" !== "ID2 GOES HERE")

Note, you have to be careful with hard coding the Ids, as they might and likely will change between environments / sandbox refreshes.