Hello all,
Find attached sample code for integrating a Google Map into your NetSuite account. It is a simple mashup that adds a tab to the customer page in view and edit mode and displays the customer's billing and shipping addresses in a scrollable/zoomable Google map.
For those of you who are curious, the mashup was built using a beforeload User Event script (for adding the Google Map UI to the customer page) and a Suitelet (for generating the map using the Google Map API). The latter script type is only available in version 2007.0 accounts.
For anyone intimidated by the script, I plan on bundling this and allowing for some end user configuration (such as API key, show multiple addresses, positioning, etc...). This will make it relatively easy to install and setup.
Note that you must visit Google's website (http://www.google.com/apis/maps/documentation/) to obtain your own API key. The API key used in this script will not work in your account.
Good luck. Any questions, comments, feedback?
/** * Generate Google Map page in IFRAME * * Implemented using a Suitelet (scriptid=customscript_google, deploymentid=customdeploy_google) **/ function googleMapPage(request, response) { /* Fetch Billing address, strip out line breaks as Google API doesn't need them. */ var address = request.getParameter('customer') != null ? nlapiLookupField( 'customer', request.getParameter('customer'), 'billaddress' ) : null if ( address != null ) address = address.replace('n', ' ') /* Fetch Shipping address, strip out line breaks as Google API doesn't need them. */ var shipaddress = request.getParameter('customer') != null ? nlapiLookupField( 'customer', request.getParameter('customer'), 'shipaddress' ) : null if ( shipaddress != null ) shipaddress = shipaddress.replace('n', ' ') response.writeLine('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); response.writeLine('<html xmlns="http://www.w3.org/1999/xhtml">') response.writeLine('<head>') response.writeLine('<meta http-equiv="content-type" content="text/html; charset=utf-8"/>') response.writeLine('<title>Google Maps JavaScript API Example</title>') /* Download Google Map API. */ response.writeLine('<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAa9-dKZt7cfQ4hPTRL71dLxT0Bw_wqVo513xmn8upi5NDlsPzxBTblog6FyLs3ddo6WdBDBIVb-q5HQ" type="text/javascript"></script>') response.writeLine('<script type="text/javascript">') response.writeLine('var map = null') /* Function for initialzing Google Map using their API and customer data. */ response.writeLine('function GLoadMap() {') response.writeLine('if (GBrowserIsCompatible()) {') response.writeLine('map = new GMap2(document.getElementById("map"));') response.writeLine('map.addControl(new GSmallMapControl());') response.writeLine('map.addControl(new GMapTypeControl());') /* Display billing address. */ response.writeLine('new GClientGeocoder().getLatLng(' + '"'+address+'",' + 'function(point){ ' + 'if (point) { ' + 'map.setCenter(point,13); ' + 'var marker = new GMarker(point); ' + 'map.addOverlay(marker); } });') /* Display shipping address. */ if ( shipaddress != null ) response.writeLine('new GClientGeocoder().getLatLng(' + '"'+shipaddress+'",' + 'function(point){ ' + 'if (point) { ' + 'var marker = new GMarker(point); ' + 'map.addOverlay(marker); } });') response.writeLine('}') response.writeLine('}') response.writeLine('</script>') response.writeLine('</head>') /* Build Google Map Page, simple container for rendering map, onload call map init API, onunload call destructor to avoid memory leaks in IE6. */ response.writeLine('<body onload="GLoadMap()" onunload="GUnload()" style="margin:0; border:0; padding:0;">') response.writeLine('<div id="map" style="width: 500px; height: 400px; margin:0; border:0; padding:0"></div>') response.writeLine('</body>') response.writeLine('</html>') } /** * Add Google Map Inline HTML field to page * * Implemented using a beforeLoad user event script deployed to the lead, customer, and prospect records **/ function googleMapForm(type, form) { if ( type == 'view' || type == 'edit' ) { /* Add Google Map tab to page. */ var tab = form.addTab( 'custpage_googlemap_tab', 'Google Map' ) form.insertTab( tab, 'general' ) var map = form.addField('custpage_googlemap', 'inlinehtml', null, null, 'custpage_googlemap_tab') /* Generate URL for Suitelet, include internalid of the current customer. */ var serverUrl = nlapiResolveURL( 'SUITELET', 'customscript_google', 'customdeploy_google' ) + '&customer='+nlapiGetRecordId(); /* Output IFRAME container for Google map page. */ map.setDefaultValue( '<iframe src="'+serverUrl+'" style="width: 504px; height: 404px; margin:0; border:0; padding:0"></iframe>' ) } } BTW - Here is a screenshot of the end result: