Share via


Property Value Estimator Code Sample

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The Property Value Estimator creates a Page Viewer Web Part that displays value estimates and property details, including a map, for home addresses in a contacts list. This mashup takes advantage of the Zillow API Network. The Zillow API Network site describes using these APIs to “turn member sites into mini real estate portals by offering Zestimate® home valuations and property details.” The Property Value Estimator sample uses the Microsoft Virtual Earth mapping Web services and Windows SharePoint Services 3.0 Web services. It also uses the Business Contacts list in Contact Manager in Microsoft Office Live Small Business.

To make this code sample work, the download includes Microsoft JScript functions to package the SOAP requests you use to communicate with Windows SharePoint Services Web services. You can use these same functions from the common JScript (olsharedlibv2.jsx) file to jump-start your development work.

NoteNote

This code sample passes the address for a contact in your Contact Manager Business Contacts list to Zillow.com to request valuation data. The data is passed over HTTP, and thus is not encrypted. No ID or name is passed with the address data. You can view the Zillow privacy policy here. Microsoft is not responsible for Zillow’s privacy policies and practices.

Add the Code Sample as a Solution

The Property Value Estimator code sample is located in the MSDN Code Gallery.

See the Sample in Action

The Property Value Estimator solution file (PropertyEstimator.olp) includes a sample Web page with a prebuilt Page Viewer Web Part so that you can see the results of the code. To view the results, do the following:

  1. To obtain a Zillow Web Services ID (ZWSID), register with Zillow.

  2. In your Microsoft Office Live Small Business account, verify that the Business Contacts List in Contact Manager contains contacts with home addresses.

  3. On the Microsoft Office Small Business Home page, at the top, click More, and then click Business Applications.

  4. On the Business Applications Home page, on the left navigation bar, click Property Value Estimator.

  5. In the library, open zillowsample.jsx for edit.

  6. In the zillowsample.jsx file, insert your ZWSID between the quotation marks in the following line of code:

    var g_strZillowId = "";       // Zillow.com ZWSID code
    
  7. Save and close the zillowsample.jsx file.

  8. In the library, click samplepage.

The Sample Web page opens in the Property Value Estimator business application, and a Page Viewer Web Part displays the Property Value Estimator sample user interface. The left side of the Web Part, under Contacts, contains a radio button for each business contact in Contact Manager that has an associated home address. Select the contact whose property you want to value.

How it Works

We combine several functions in the zillowsample.jsx file to make this mashup.

Get contact addresses available for value estimation

To obtain a list of the items in the Business Contacts list of Contact Manager, the Property Value Estimator code uses a Web service provided by Windows SharePoint Services. The zillowsample.js file does the following:

  1. A global variable is set to point to the Business Contacts list in Contact Manager.

    var CONTACTSLISTNAME = 'Business Contacts';
    
NoteNote

If you downloaded this code sample before January 2008, the CONTACTSLISTNAME is set to 'Contacts'. You must update the name of the list to 'Business Contacts'.

  1. The initialize function sets the Web context for this sample to Contact Manager (WebBCM).

    var strWebContext = document.location.protocol + "//" + document.location.hostname;
        if(document.location.port != null)
        {
            strWebContext += ":" + document.location.port;
        }
        strWebContext +="/WebBCM";
    
  2. The initialize function creates a WssSoap object using this Web context.

    var g_oWssSoap = null;  
    g_oWssSoap = new WssSoap(strWebContext);
    
  3. The initialize function calls the getContacts function in the zillowsample.jsx file.

    getContacts();
    
  4. The getContacts function calls the getAllListItems method for the WssSoap object from the olsharedlibv2 file. It passes the list name, the array of field names to be returned, and the function name to call on completion.

    g_oWssSoap.getAllListItems(CONTACTSLISTNAME,
            new Array("Title", "FirstName", "HomeAddressStreet", "HomeAddressCity", "HomeAddressStateOrProvince", "HomeAddressPostalCode"),onGetContactResults);
    
  5. The getAllListItems method starts the process to package a SOAP request and post it to the GetListItems method in the Lists Web service in Windows SharePoint Services 3.0.

Talk to Zillow

The process used in the zillowsample.jsx file to communicate with the Zillow APIs is as follows:

  1. The getZillowInformation function constructs the address to be passed to the Zillow Web service. The address is constructed by using the items retrieved from the Business Contacts list as described earlier. The items are added to the vParameters array.

    var oCurrContact = g_vContacts[g_iSelectedContactIndex];
    
        // Parse the selected address value into params for Zillow RPCs.
        var vParameters = new Array();
        vParameters["zws-id"] = g_strZillowId;
        vParameters["address"] = oCurrContact.strAddressStreet;
        if(oCurrContact.strAddressCity && oCurrContact.strStateOrProvince)
        {
            vParameters["citystatezip"] = oCurrContact.strAddressCity + " " + oCurrContact.strStateOrProvince;
        }
        else
        {
            vParameters["citystatezip"] = oCurrContact.strHomeAddressPostalCode;
        }
    
  2. The vParameters array is then passed as a parameter in a zillowRPC function call to issue an asynchronous XmlHttpRequest GET to Zillow's GetSearchResults API. For more information about the proxy required to accomplish this task, see the “Create a proxy effect” section in this article.

    zillowRPC("GetSearchResults", vParameters, displayZillowSearchResults);
    
  3. The Zillow GetSearchResults API finds a property for the specified address. The content returned contains:

    • The address for the property.

    • The Zillow Property ID (ZPID).

    • The current Zestimate.

    • The date on which the Zestimate was computed.

    • A valuation range.

    • The Zestimate ranking for the property within its ZIP code.

    • If no exact address match for a property is found, a list of closely matching properties is returned.

Create a proxy effect

For the zillowRPC function to make a Web service call to Zillow, this code sample must relay the call using a server proxy. This proxy effect is achieved through a Data Form Web Part on an ASP.NET server (.aspx) page.

To use the .aspx file as a proxy, the Property Value Estimator code sample takes the following steps:

  1. The getZillowInformation function calls the zillowRPC function as described earlier.

  2. The zillowRPC function concatenates the proxy name with GetSearchResults, which was passed as a parameter to the function to create the URL for the HttpRequest.

    var strFullUrl = strAction + "ZillowProxy.aspx";
    
  3. The zillowRPC function then performs an HTTP GET on the .aspx page and calls the zillowCallback function.

    g_oHttpRequest = new HttpRequest(strFullUrl, "GET", vParameters);
        g_oHttpRequest.sendRequest(zillowCallback);
    
  4. The zillowCallback function finds the XML data island that was output onto the page and returns the information to a callback function.

Create the property map

The displayPropertyMap function does the following:

  • Displays the division of the map that contains the property for which you want the value.

  • Creates a Virtual Earth map object and centers it on the address for the property.

  • Creates a Virtual Earth pushpin object and sets caption information for it.

  • Adds the pushpin to the map.

You can view this map by scrolling down in the Page Viewer Web Part on the sample page.

Display the results

The displayZillowSearchResults function is the callback function passed to the zillowCallback function in this code sample. It uses several more zillowRPC calls to collect valuation and property detail information on the property. Then it displays the map and all of the other Zillow information about the property in a Page Viewer Web Part on the sample page.

See Also

Concepts

Contact Map Code Sample

Interact with Lists the AJAX Way