[SalesForce] onClick JavaScript button — Add simple If condition

I am kinda new person in JavaScript, please help me our here with small doubt

What I am missing here …….. I want to correct this one….

I am trying this :

if( {!Account.CID__c}){
    window.open( '{! SUBSTITUTE($Setup.CustomSetting__c.Link__c,"[#CID#]",Account.AnotherField__C)}');
}
else{
 window.open( '{! SUBSTITUTE($Setup.CustomSetting__c.Link__c,"[#CID#]",Account.CID__c )}')
}

GOT ERROR "Unexpected Token )"

Earlier I was having

window.open( '{!SUBSTITUTE($Setup.CustomSettings__c.Link__c,"[#CID#]",Account.CID__c)}');

And I just want to add one more Condition here i.e.

If(CID__C == null){
  // put another AnotherField__C in place of that.
}else{ 
   //put Account.CID__C ...which we were having earlier 
}

https://stackoverflow.com/questions/33396999/onclick-javascript-button

Best Answer

Change your script to this:

if( '{!Account.CID__c}' == 'null' || '{!Account.CID__c}' == ''){
    window.open( '{! SUBSTITUTE($Setup.CustomSetting__c.Link__c,"[#CID#]",Account.AnotherField__C)}');
}
else {
    window.open( '{! SUBSTITUTE($Setup.CustomSetting__c.Link__c,"[#CID#]",Account.CID__c )}')
}