[SalesForce] Using {!User.Profile} merge field in Javascript if statement

I have a business requirement where a new Quote record cannot be generated for a couple different Opportunity types. If the user tries, they get an alert. I've overridden the standard New Quote button with a javascript button. But a new requirement came in yesterday saying that one profile can generate contracts regardless of Opportunity Type. When I added this second condition to the if statement with an && logical, it seems to abort after the if and not proceed onto the other conditionals. A slightly modified version of the code is below.

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 
var cQuote = new sforce.SObject("Quote");
var QuoteRecord = sforce.connection.query("Select OpportunityId, Id From Quote where OpportunityId='{!Opportunity.Id}' "); 
var records = QuoteRecord.getArray("records");
if('{!Opportunity.Type}'=='Example Type' && '{!User.Profile}' != 'Example Profile Type') {
    alert("A quote record cannot be created for this Opportunity Type.");
    window.parent.location.href=window.parent.location.href;
}
else if(records[0] != null) { 
    alert('A Quote Entry already exists.'); 
    window.parent.location.href=window.parent.location.href;
}
else {
    cQuote.Name="Do Not Edit";
    cQuote.Status="Active";
    cQuote.Opportunityid="{!Opportunity.Id}";
    var result=sforce.connection.create([cQuote]);
    if (result[0].getBoolean("success")) {
        window.parent.location.href='/'+result[0].id;
    }
}

I checked the javascript console – the only difference between the old button without the !User.Profile condition and the new button with it is that the new button returns two error messages that say "Refused to set unsafe header "User-Agent". See below image for more detail. I would really appreciate some insight on this.
Here's the console error

Best Answer

This example worked for me:

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

if('{!Opportunity.Type}' == 'New Customer' && '{!$Profile.Name}' != 'System Administrator') {
    alert("A quote record cannot be created for this Opportunity Type.");
    window.parent.location.href=window.parent.location.href;
}
else {
alert('Your Sys Admin');
}

If I change the Profile check to be something else, like "System Admin1", then the IF fails, and the redirect fires.

Related Topic