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
Scott BradyScott Brady 

Visualforce Page to replace custom button

I currently have a button that is designed to allow our users to take ownership of their Incident (custom object, Remedyforce related) and put the status "In Progress".  This button is a custom detail page button that is located on the "record details" page of the console view.  Here is the code:
 
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
 
try{
var incidentToUpdate = new sforce.SObject("BMCServiceDesk__Incident__c");
 
/*
The next 3 lines of code select the incident to update (current page the user is on), selects the user to assign as the owner of the ticket (current user clicking the button) and updates the ticket status to "in progress"
*/
incidentToUpdate.Id = "{!BMCServiceDesk__Incident__c.Id}";
incidentToUpdate.OwnerId = "{!$User.Id}";
incidentToUpdate.BMCServiceDesk__FKStatus__c = "a4V80000000PBFi";
 
/*
this sets the variable for categoryId = Category ID on the ticket. This is done because we are selecting the category Id to input in the lookup field (category).
*/
 
var categoryId = "{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategoryId__c}";
 
/*
The next block of If/Else If statements are what reassigns the category. First if statement checks to see if the first letter of the category is an A, for 'Alert'. If so, it will update the categoryId (variable) to 'Incident'. Next, it will do the same check to see if the first letter is an I, for 'Incident', but will not change the category. The same for the next if statement, but for R and 'Request'
*/
if(
"{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategory__c}".charCodeAt(0) == 65
){
categoryId = "a2k80000000Gqyj";
}
else if(
"{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategory__c}".charCodeAt(1) == 110
){
categoryId = "a2k80000000Gqyj";
}
else if(
"{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategory__c}".charCodeAt(0) == 82
){
categoryId = "a2k80000000Gqyy";
}
else if(
"{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategory__c}".charCodeAt(1) == 72
){
categoryId = "a2k340000008i8m";
}
incidentToUpdate.BMCServiceDesk__FKCategory__c = categoryId;
 
var result = sforce.connection.update([incidentToUpdate]);
 
if(result[0].success == "true"){
location.reload();
}
else{
alert(
"An Error has Occurred. Error: " +
result[0].errors.message
);
}
}
catch(e){
alert(
"An Error has Occurred. Error: " +
e
);
}


 
Ignore the notes that are included, as they are meant for my manager who may need to make edits to the button when i am not present.  My question is to figure out/ask if this can be changed into a visualforce page/action that can be invoked via the Custom Action feature within the Remedyforce Console (Remedyforce is an add-on to Salesforce). RIght now, Custom Actions needs to invoke a URL, and unfortunately, that's forcing me to change this button into a visualforce page that I could use for my URL.  I also know that I could perhaps "URL hack", but the Remedyforce console does not like that, as the URL hack redirects me back to the standard Incident object within Salesforce rather then than the Console view.  The button itself does work and does make the updates I want it to, but I'd like to have it as a custom action.
Any ideas?