+ Start a Discussion
KlivingstonKlivingston 

Change Record Type on the go

Hi All

Description: We have many record types for our Account object. many of them showing relevent info for our staff but one shows relevent info for our customers. usually our staff need to show those info to our customer and they usually dont have access to change the record type.

We would like to have a button on the customer page to change the record type between those two record types (Customer and staff view).

I have a custom button here that allows me to change the record types to our Customer view record types. But that change is permanent and I need to be able to change that to the original layout straight away.

Is there a way to achieve this? if so can you please help me with code.

Thanks in advance.


Custom Button 


Code:

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


var ac= new sforce.SObject("Account");
ac.Id = '{!Account.Id}';

ac.RecordTypeId = '012g00000004PVM';
var result = sforce.connection.update([ac]);
 
//ac.RecordTypeId = '01220000000TwQQ';
//var result = sforce.connection.update([ac]);

if (result[0].success=='false') {

     alert(result[0].errors.message);

} else {

     location.reload(true);

}
Vamsi KrishnaVamsi Krishna
Hi
I would suggest you to add another button similar to this one, say call it "Staff View" and change the record type back to the staff record type.

since you cannot control/predict how long your staff and customer will need to view each layout, you shouldn't be automating the record type change from staff -> customer -> back to staff.

if you still want to automate the record type change, you can use javascript timeout function and then change the record type after a certain amount of time.
KlivingstonKlivingston
Hi

Thanks for your comment, I think having two buttons is better as well. What I have done so far is I added only a button to our page layout (Customer View), this will change the RecordType to Customer view layout. Then there is only one button in Customer page layout called Staff View which should takes us back to Staff view.

With the Customer view button it is easy as the Record type will be static where we have only one record type for customer layout, but I am not sure how to retrieve the staff view Record type and save it in the button.

it would be something like this but I am not familiar with JS much:

get the current Record Type
Save it in a variable (which will be accessible by the Staff View botton)

Thanks