What's best way to update records based on record type using custom button.
Below code partially works and fields updates inside 'If block' doesn't work. What I'm missing here ?
{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Case)};
var newRecords = [];
if (records[0] == null)
{
alert("Please select at least one row")
}
else
{
for (var n=0; n<records.length; n++) {
var c = new sforce.SObject("Case");
c.id = records[n];
c.Status = "Canceled";
if('{!Case.RecordTypeId}' == '012d0000000xFShAAM'){
c.Type= "Other";
c.Sub_Type__c= "Other";
}
else if('{!Case.RecordTypeId}' == '012d0000000P2ZrAAK'){
c.CanceledReason__c="Spam";
}
c.ownerid='{!$User.Id}';
newRecords.push(c);
}
result = sforce.connection.update(newRecords);
window.location.reload();
}