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
BeekmanBeekman 

Custom Button-Onclick Java Script error

Hello,

 

No matter how hard I try I cannot get a simple IF to work.  It keeps telling me that it is missing a ";" on line 5.  If I get rid of the IF statement it works fine but I dont want to overwrite the fields if they are already populated.  Cannot use a workflow as it doesn't understand records "--r" to get Lookup fields.

 

Any suggestions?

 

Even a simple IF fails...

 

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

IF ( 0 > 1 ) {
    alert('worked');
}

 

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

var a = new sforce.SObject("Opportunity");

IF ( "{!Opportunity.Ship2Addr1__c}" == " ") {
	//Getting Id of Current object
	a.Id =  "{!Opportunity.Id}";
	//Updating fields
	try 	{
		var MySiteAddress = sforce.connection.query("Select Id, Name, Site_Street1__c, Site_City__c, Site_State__c, Site_ZIP__c, Site_Country__c, Site_Phone_Number__c from EnvySite__c where Id = '{!Opportunity.EnvySiteId__c}' Limit 1");
		var recs = MySiteAddress.getArray("records");
		if ( recs.length > 0 ) {
			a.Ship2_Attn__c = "Manager";
			a.Ship2CoName__c = recs[0].Name;
			a.Ship2Addr1__c = recs[0].Site_Street1__c;
			a.Ship2City__c = recs[0].Site_City__c;
			a.Ship2St__c = recs[0].Site_State__c;
			a.Ship2Zip__c = recs[0].Site_ZIP__c;
			a.Ship2Country__c = recs[0].Site_Country__c;
			a.Ship2_Phone__c = recs[0].Site_Phone_Number__c;
		} else {
			alert('Cannot find Site attached to Opportunity.');
		} catch (e) {
        	alert('Exception Error in finding Site. Please try again.: ' + e);
		}
}

//Update Records in the array to database
sforce.connection.update([a]);

//Reload page
location.reload(true);