Google Maps for Organisations

A few weeks ago, in this post, I explained how to embed Google Maps on RightNow CX, in order to quickly see the Contacts’s address using the information in the RightNow database.

Some of you asked if this was possible to do with Organisations. The answer was: unfortunately it is not as straight forward as with Contact, and there is two reasons for that:

a) The Address field in Organisation – “Oaddr” – is different than that in the Contact. It is a collection of addresses that has two types: Billing and Shipping. These are controlled by objects “Organization Addresses” and “Organization Address Types”.

b) Address values in Organisation are not available to get directly. “Oaddr” is expressed as string XML data of the following form:

<Addr Street=”123 main st” City=”Bozeman” ProvId=”23″ PostalCode=”59718″ CountryId=”1″ />.

The suggestion to get this done was to use a Desktop Integration with RightNow Connect JavaScript API in 4 stages:

  1. Get and parse the Organisation address
  2. Retrieve the values (Street, City, Province, Postal Code, Country)
  3. Build a Google Maps URL with the values
  4. Navigate to Google Maps using “window.location”

The solution is then:

  • Step 1: Create an HTML file with the JavaSCript code to build the Google Maps URL

<html>
<head>
<script type=“text/javascript”>

function getAddress()
{
var selection=document.getElementById(‘address_type’).value;
//0 for billing addr and 1 for shipping addr
var address = window.external.Org.OAddresses;
var org=window.external.Org;
var provinceName;
var countryName;

//Parsing the XML into object
var xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async = “false”;
xmlDoc.loadXML(address);

//Retrieving all the fields of selected Organisation Address
var desiredAddress=xmlDoc.getElementsByTagName(“OAddresses”)[0];

var street=desiredAddress.getElementsByTagName(“Addr”)[selection].getAttribute(“Street”);
var city=desiredAddress.getElementsByTagName(“Addr”)[selection].getAttribute(“City”);
var provId=desiredAddress.getElementsByTagName(“Addr”)[selection].getAttribute(“ProvId”);

var postalCode=desiredAddress.getElementsByTagName(“Addr”)[selection].getAttribute(“PostalCode”);
var countryId=desiredAddress.getElementsByTagName(“Addr”)[selection].getAttribute(“CountryId”);

//Fetching Province Name corresponding to provinceID retrieved
var provLabels = org.GetNameValues(“ProvId”);
xmlDoc.loadXML(provLabels);
var x=xmlDoc.getElementsByTagName(“Item”);
for (i = 0; i < x.length; i++)
{
var provAttlist=x.item(i).attributes;
var provAtt=provAttlist.getNamedItem(“Id”);
if (provAtt.value==provId)
{
provinceName= provAttlist.getNamedItem(“Name”).value;
}
}

//Fetching Country Name corresponding to countryId retrieved
var countryLabels = org.GetNameValues(“CountryId”);
xmlDoc.loadXML(countryLabels);
var y=xmlDoc.getElementsByTagName(“Item”);
for (i = 0; i < y.length; i++)
{
var countAttlist=y.item(i).attributes;
var countAtt=countAttlist.getNamedItem(“Id”);
if (countAtt.value==countryId)
{
countryName= countAttlist.getNamedItem(“Name”).value;
}
}

//Building the google maps URL
var finalAddress=street+” “+city+” “+postalCode+” “+ provinceName+” “+countryName;
window.location=”http://maps.google.co.in/maps?hl=en&q=”+finalAddress;
}

function ondataupdated(obj)
{
getAddress();
}

</script>
</head>
<body onload=getAddress()>
</body>
</html>

  • Step 2: Upload the HTML file to a server via FTP (I normally use FileZilla).
  • Step 3: Add a new tab to the Organisations Workspace and drag and drop a browser control into the tab

rn1

  • Step 5: Select the browser control, go to the Design tab > Options section, and put the URL path of the HTML file into the URL field.

rn2

  • Step 6: Select the browser control, go to the Design tab > Options section, and un-check the Delay Page Load check box.

rn3

Now, whenever you open an Organisation, and navigate to the “Map” tab, you will automatically see the Organisations’s address on the map.

Thank you to Bhagwan Singh Mer (Lead Consultant at Wipro Technologies) and Jens Lundell (Oracle RightNow Workflow Development Manager) for their help on this requirement. Special thank you to Saurabh Gupta (Consultant at Wipro Technologies) as it was him that scripted the JavaScript code.