Code Sample for a Custom Button That Gets a Shipping Address to Pass to an External Site

The following code creates a custom button labeled Map Shipping Address on the Account Detail page. When the button is clicked, the shipping address is passed to an external URL, in this case, the URL for Google Maps.

// example: create a map button 
// entry point for running custom code
oraclecrmod.onReady(function()
{

		// when on the Account  Detail page
		if(oraclecrmod.ctx.object == "Account" && oraclecrmod.ctx.isDetailPage())
		{

			// define map function
			function map()
			{

				var wholeAddress = "";
				if (oraclecrmod.getField("Ship To Street Address") != null)
				wholeAddress += oraclecrmod.getField("Ship To Street Address").getValue() + " ";
				if (oraclecrmod.getField("Ship Street Address 2") != null)
				wholeAddress += oraclecrmod.getField("Ship To Street Address 2").getValue() + " ";
				if (oraclecrmod.getField("Ship Street Address 3") != null)
				wholeAddress += oraclecrmod.getField("Ship To Street Address 3").getValue() + " ";
				if (oraclecrmod.getField("Ship To County") != null)
				wholeAddress += oraclecrmod.getField("Ship To County").getValue() + " ";
				if (oraclecrmod.getField("Ship To Postal Code") != null)
				wholeAddress += oraclecrmod.getField("Ship To Postal Code").getValue() + " ";
				if (oraclecrmod.getField("Ship To Country") != null)
				wholeAddress += oraclecrmod.getField("Ship To Country").getValue() + " ";
				window.open("http://maps.google.com?q=" + encodeURIComponent(wholeAddress));

			}

        
			// get the title bar
			titleBar = oraclecrmod.getTitleBar("AccountFormTB");
			// create the new map button
			button = oraclecrmod.createButton({id:"mapButton", text:"Map Shipping Address", 
			parent:titleBar});
			// associate the map function with the button click event
			button.on("click", map);


			}
});