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
Pavan Kumar 1072Pavan Kumar 1072 

Issue with javascript button

I have a javascript button in my organization to restrict quote creation for sales users when respective criteria met
If Person is trying to create a quote it will check whether it is assigned to the manager or not with how many days prospect with us and so.
 
But it is not working as expected even it didn't meet the first criteria. It is displaying an alert message.
It meets the first if criteria But it is routing to respective URL.
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var Subrecords = sforce.connection.query("SELECT Id,name from Zuora__Subscription__c where Zuora__Account__c ='{!Opportunity.AccountId}'");
records = Subrecords.getArray("records");
if('{!$User.Type__c}' == 'Bangalore' && '{!Account.Account_Status__c}' == 'Active / Green' && '{!Account.Age_of_Account_Days__c}' > 180 && '{!ISPICKVAL( Account.AM_sales__c , 'Yes')}' && '{!$User.Username}' !== 'sample@azs.com')
{
alert("You don't have sufficient access to generate quote"); 
}
else 
{
if(records.length > 0)
{
window.location.href='https://zqu.ap4.visual.force.com/apex/quoteEnhancement?oppId={!Opportunity.Id}&quoteType=Subscription&stepNumber=1';
}
else
{
window.location.href='https://zqu.ap4.visual.force.com/apex/CreateQuote?oppId={!Opportunity.Id}&quoteType=Subscription&scontrolCaching=1&stepNumber=2';
}
}
I don't where I missed it