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.

6 thoughts on “Google Maps for Organisations

  1. Hi Bhagwan,

    I have uploaded file Javascript file on cyberduck . But i open organization workspace after entering Billing and Shipping Address . Map tab show error “This page cannot diaplay the webpage” . Please revert .

  2. Can you upload it as a file attachment into Service Cloud and copy the URL here. Doesn’t seem to work when I tried it. This code was generated in 2013, so I wonder if some of the schema names have changed in the last 2 years, and therefore the code needs re-writing. any thoughts?

    1. Hi Ishan,

      I have the file uploaded into my personal website, and therefore didn’t want to share it publicly. I will send you an email with the code I’m using.

  3. Hello,

    Great solution! I am definitely going to use it.

    I know that this question doesn’t relate to this post, but is related to JS API.

    I am trying to set/get values from a TextBox Control from a Workspace through the Javascript API and since it doesn’t have an ID or Name I am not being able to do so. Is there any way to accomplish this using JS API?

    Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s