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
Kurt A BrimberryKurt A Brimberry 

Custom JavaScript Button not Working when Looking Up Custom Field

Hello.  I have a custom List Button that calls some onClick Javascript.  The button works for all but the first argument, and I can't seem to wrestle this to the ground.  We have 4 Account record types, and 4 matching Contact records types.  When you create a new contact (from the Account related list) on an account, I want to skip the record type slection page entirely, since the Contact's record type is related to the Account's in a 1:1 fashion.

To do this, I created a custom formula field on the Account with the developer name for the Record Type.  Then I wrote this JS.  It works for 3 of the 4, but for End User it fails.  Any Thoughts?  Thanks in advance!
 
{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")} 

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

var agmtStats = sforce.connection.query("SELECT Account_Record_Type_for_Flows__c FROM Account WHERE id = '{!Account.Id}'"); 

records = agmtStats.getArray("records"); 
var agmtStat = records[0].Account_Record_Type_for_Flows__c; 

if(agmtStat == 'End User'){ 
alert('System Out'); 
} 
else if(agmtStat == 'Competitor'){ 
window.open('/003/e?retURL={!Account.Id}&accid={!Account.Id}&RecordType=0120j0000000EZh&ent=Contact '); 
} 
else if(agmtStat == 'Distributor'){ 
window.open('/003/e?retURL={!Account.Id}&accid={!Account.Id}&RecordType=0120j0000000EZX&ent=Contact '); 
} 
else if(agmtStat == 'Production Partner'){ 
window.open('/003/e?retURL={!Account.Id}&accid={!Account.Id}&RecordType=0120j0000000EZc&ent=Contact'); 
} 
else{ 
alert('Please Send Ticket to Helpdesk'); 
}