SharePoint Developer Tips: Show List Items on a Map

  • By IncWorx Team
  • 19 Jul, 2017
Maximize your SharePoint investment by getting the most out of it. You harness the true power of SharePoint when you leverage its customizability to meet the specific needs of your organization.
Disclaimer: The solutions in this series are not intended to provide a complete, best practices, or warranted solution, but are intended to demonstrate possibilities and provide you with examples that you can begin to build upon. Do not attempt exercises in a production environment. Any use of information contained in this article is strictly at your own risk. If you need additional SharePoint support or advisory hours, please don’t hesitate to contact IncWorx. We’re here to help you get the most out of SharePoint.

Overview

This post demonstrates the display of SharePoint list items on a map using JSLink and the Google Maps JavaScript API.

Summary

In the steps that follow, we will create a new custom list named Companies. The Title field will hold the company name and a new column named Location will hold the company address information. We will use a Content Editor Web Part placed above the list view as the container for the map. JavaScript will be used to call the Google API for generating the map, obtaining the geolocation of each list item’s location, and adding the markers to the map. JSLink is used to associate the JavaScript with the list view which is executed client-side during the list view’s rendering process (client-side rendering).

Prerequisites

Google Maps API Key – if you want to follow along and implement the solution on your own you will need an API key from Google .

Versions

SharePoint 2013, Office 365

Step 1: Go to Site Contents and choose New --> List

Step 2: Name the list Companies and click the Create button

Step 3: Add a column of type Single line of text

Step 4: Name the column Location and click the Create button

Step 5: Populate the list with sample company names and locations

Step 6: Using your favorite editor create and save a file named JSLinkMapView.js and add the following (be sure to enter your own Google API key ):

document.write('<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<<your google api key here>>"></script>');

function RegisterCustomOverrides() {
    var obj = {};
    obj.Templates = {};
    obj.Templates.OnPostRender = LoadMap;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(obj);
}

function LoadMap(ctx) {

    var mapOptions = {
        center: new google.maps.LatLng(42, -88),
        zoom: 6
    };

    var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
    var geo = new google.maps.Geocoder();
    var bounds = new google.maps.LatLngBounds();
    var rows = ctx.ListData.Row;
    var idx = 0;

    for (var i = 0; i < rows.length; i++) {

        geo.geocode({'address':rows[i]["Location"]},function(results, status) {
            new google.maps.Marker({map: map, position: results[0].geometry.location, title: rows[idx++].Title});
            bounds.extend(results[0].geometry.location);
            map.fitBounds(bounds);
        });
    }
}

RegisterModuleInit("/SiteAssets/JSLinkMapView.js", RegisterCustomOverrides);
RegisterCustomOverrides();
Step 7: Upload the JSLinkMapView.js file to the SiteAssets document library of your site

Step 8: Return to the Companies list and click Return to classic SharePoint (note, at the time of this writing Microsoft’s new “modern pages” do not support many of SharePoint’s customization features including JSLink)

Step 9: From the Site Actions menu choose Edit Page

Step 10: Click Add Web Part and add a Content Editor Web Part to the page

Step 11: With the Content Editor Web Part now added above the list items, click to edit the web part and activate the ribbon options, then choose Edit Source

Step 12: Paste the following in the content editor source window and click the OK button (this will be used as the container for the Google map):

<div id='map-canvas' style='border: 1px solid black; height: 200px;'/>

Step 13: Click Edit Web Part from the list view web part’s context menu

Step 14: Expand Miscellaneous and paste the following in the JSLink field and click OK:

 

~site/SiteAssets/JSLinkMapView.js

Step 15: Click the Stop Editing button on the ribbon

Final Result: SharePoint list items displayed as markers on a map

We hope you've enjoyed this brief introduction to JSLink.  If you have another idea for a DIY SharePoint Series topic submit it via the comments section below.  All ideas will be considered for future posts.

The IncWorx SharePoint Consulting Blog

By IncWorx Team 04 Dec, 2017
In an age of limitless information at our fingertips, I’m often frustrated as I try to weed through it all just to find the nuggets I’m looking for.
By IncWorx Team 04 Dec, 2017

For the last decade, SharePoint deployments have consisted of on-premise deployments which require many servers, licenses, and ongoing care and feeding. In this model there were typically one or more administrators or developers that were responsible for ensuring the farm was healthy. This typically equated to server farms that had not been patched in years or had any maintenance done whatsoever. It was just easier to leave those servers alone because nobody really knew much about SharePoint.

With the creation of the 365-application stack and movement of applications like Exchange and SharePoint started occurring, so did the start of the changing support landscape.

Fast forward to 2017 and cloud adoption has skyrocketed and the 365 stack has been maturing and adding functionality rapidly. As some of our clients have transitioned to Office 365 in varying capacities they have asked the question “Do I really need a support contract since I moved to the cloud?”

The answer to this is a resounding “YES”.

A common thought is since I don’t have the servers to be managed and maintained then there is really nothing more to support, I just use the product. Although the back-end administration and management has largely gone away, there Is still a need for product expertise for you to implement the business process, reporting, automation, and other functionality that will provide true ROI for your investment in the platform.

This is a huge benefit to our clients and can be as well for your organization. All those hours that used to be spent patching, monitoring, and maintaining your SharePoint environment can now be spent working with the business to gather requirements and developing longer term strategy for usage of the 365 platform and applications that will deliver the required business functionality.

It is exciting to see the tremendous benefits for our clients in this shift to cloud services such as Office 365, Azure, and AWS. If you are contemplating a move to the cloud and have additional questions reach out and we will be happy to assist.

By IncWorx Team 07 Nov, 2017

In this DIY Post, learn how to display dynamic information on a SharePoint workflow initiation form with SharePoint Lists, rather than InfoPath.

Environments: SharePoint 2013 and SharePoint O365

Scenario: You need to display dynamic information on a SharePoint workflow initiation form.

Solution: Utilize an OOTB SharePoint list to be used as your workflow initiation form instead of using the InfoPath option to customize the OOTB designer workflow form.

Description: I’ve ran into situations where the requirements dictated that dynamic information be displayed in SharePoint (not via email) when a workflow is being initiated.  This post will describe how to use a “supporting” custom SharePoint list to display the initiation form information and trigger the workflow against the “target” list.  This solution only uses client side technologies: jQuery and SharePoint’s CSOM.


Step 1 – Create your SharePoint List That Requires a Workflow

Create a new SharePoint list that will ultimately have the workflow ran against. Here is the example list that I am using for this post:

List name = “RandomApproval”

By IncWorx Team 06 Nov, 2017

There is a known bug in SharePoint (2013 & 2016) Distributed Cache when using AppFabric pre-CU4. These issues can be fixed by applying the latest AppFabric CU and enabling the background garbage collection feature. It is also recommended to make the changes to the Distributed Cache and STS configs that we have outlined in our process.

Since Distributed Cache is involved in caching credentials in a SharePoint environment it is not surprising to find out that a misconfiguration of this cache can cause a wide variety of issues that can be difficult to pinpoint. In our experience we have seen this issue manifest itself in the following ways.

Primarily, in ULS, we see the following errors:

Product: SharePoint Foundation

Category: DistributedCache

Level: Unexpected

Message:

Unexpected error occurred in method 'GetObject' , usage 'Distributed Logon Token Cache' - Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<errca0018>:SubStatus<es0001>:The request timed out..

Additional Information : The client was trying to communicate with the server : net.tcp://cacheserver.example.com:22233

 at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody, RequestBody reqBody)

 at Microsoft.ApplicationServer.Caching.DataCache.InternalGet(String key, DataCacheItemVersion& version, String region, IMonitoringListener listener)

 at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass49.<get>b__48()

 at Microsoft.SharePoint.DistributedCaching.SPDistributedCache.GetObject(String key)'.</get></es0001></errca0018>

 

Product: SharePoint Foundation

Category: DistributedCache

Level: Medium

Message:

Unexpected error occurred in method 'GetObject' , usage 'Distributed Logon Token Cache' - Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<errca0017>:SubStatus<es0006>:There is a temporary failure. Please retry later. (One or more specified cache servers are unavailable, which could be caused by busy network or servers. For on-premises cache clusters, also verify the following conditions. Ensure that security permission has been granted for this client account, and check that the AppFabric Caching Service is allowed through the firewall on all cache hosts. Also the MaxBufferSize on the server must be greater than or equal to the serialized object size sent from the client.).

Additional Information : The client was trying to communicate with the server : net.tcp://cacheserver.example.com:22233  

 at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody, RequestBody reqBody)  

 at Microsoft.ApplicationServer.Caching.DataCache.InternalGet(String key, DataCacheItemVersion& version, String region, IMonitoringListener listener)  

 at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass49.<get>b__48()  

 at Microsoft.SharePoint.DistributedCaching.SPDistributedCache.GetObject(String key)'.</get></es0006></errca0017>

Product: SharePoint Foundation

Category: DistributedCache

Level: Medium

Message:

Token Cache: Failed to get token from distributed cache for '0#.f|provider|username'.(This is expected during the process warm up or if data cache Initialization is getting done by some other thread).

Exception: 'Microsoft.SharePoint.DistributedCaching.SPDistributedCacheClientRequestTimeOutException: Communications with the cache cluster has experienced a delay past the timeout value,please increase the RequestTimeout of the client. ---> Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<errca0018>:SubStatus<es0001>:The request timed out..

Additional Information : The client was trying to communicate with the server : net.tcp://cacheserver.example.com:22233  

 at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody, RequestBody reqBody)  

 at Microsoft.ApplicationServer.Caching.DataCache.InternalGet(String key, DataCacheItemVersion& version, String region, IMonitoringListener listener)  

 at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass49.<get>b__48()  

 at Microsoft.SharePoint.DistributedCaching.SPDistributedCache.GetObject(String key)     -

 -- End of inner exception stack trace ---  

 at Microsoft.SharePoint.DistributedCaching.SPDistributedCache.GetObject(String key)  

 at Microsoft.SharePoint.IdentityModel.SPDistributedSecurityTokenCache.GetObject(String key)  

 at Microsoft.SharePoint.IdentityModel.SPTokenCache.TryGetCachedToken(String cacheKey)'.</get></es0001></errca0018>

 

Product: SharePoint Server Search

Category: QueryCache

Level: Unexpected

Message:

SearchDistributedCache::PutAction() - Failed due to exception = 'Microsoft.Office.Server.DistributedCaching.SPDistributedCacheClusterDownException: Cache cluster is down, restart the cache cluster and Retry ---> Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<errca0017>:SubStatus<es0006>:There is a temporary failure. Please retry later. (One or more specified cache servers are unavailable, which could be caused by busy network or servers. For on-premises cache clusters, also verify the following conditions. Ensure that security permission has been granted for this client account, and check that the AppFabric Caching Service is allowed through the firewall on all cache hosts. Also the MaxBufferSize on the server must be greater than or equal to the serialized object size sent from the client.).

Additional Information : The client was trying to communicate with the server : net.tcp://cacheserver.example.com:22233

 at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody, RequestBody reqBody)

 at Microsoft.ApplicationServer.Caching.DataCache.InternalPut(String key, Object value, DataCacheItemVersion oldVersion, TimeSpan timeout, DataCacheTag[] tags, String region, IMonitoringListener listener)

 at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass25.<put>b__24()

 at Microsoft.ApplicationServer.Caching.DataCache.Put(String key, Object value, TimeSpan timeout)

 at Microsoft.Office.Server.DistributedCaching.SPDistributedCache.Put(String key, Object value)

 --- End of inner exception stack trace ---

 at Microsoft.Office.Server.DistributedCaching.SPDistributedCache.Put(String key, Object value)

 at Microsoft.Office.Server.Search.Query.SearchDistributedCache.PutAction(String key, Object value)'</put></es0006></errca0017>

 

Product: SharePoint Server Search

Category: QueryCache

Level: Unexpected

Message:

DistributedSearchResultsCache::Get() - Failed due to exception = 'Microsoft.Office.Server.DistributedCaching.SPDistributedCacheClusterDownException: Cache cluster is down, restart the cache cluster and Retry ---> Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<errca0017>:SubStatus<es0006>:There is a temporary failure. Please retry later. (One or more specified cache servers are unavailable, which could be caused by busy network or servers. For on-premises cache clusters, also verify the following conditions. Ensure that security permission has been granted for this client account, and check that the AppFabric Caching Service is allowed through the firewall on all cache hosts. Also the MaxBufferSize on the server must be greater than or equal to the serialized object size sent from the client.).

Additional Information : The client was trying to communicate with the server : net.tcp://cacheserver.example.com:22233

 at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody, RequestBody reqBody)

 at Microsoft.ApplicationServer.Caching.DataCache.InternalGet(String key, DataCacheItemVersion& version, String region, IMonitoringListener listener)

 at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass49.<get>b__48()

 at Microsoft.Office.Server.DistributedCaching.SPDistributedCache.GetObject(String key)

 --- End of inner exception stack trace ---

 at Microsoft.Office.Server.DistributedCaching.SPDistributedCache.GetObject(String key)

 at Microsoft.Office.Server.Search.Query.SearchResultsDistributedCache.Get(String key)'</get></es0006></errca0017

 

 

Resolution:

Step 1

Modify the Distributed Cache Logon Token Cache settings by using PowerShell to run the following commands:

Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache

$DLTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache

$DLTC.maxBufferPoolSize = "1073741824"

$DLTC.maxBufferSize = "33554432"

$DLTC.requestTimeout = "3000"

$DLTC.channelOpenTimeOut = "3000"

$DLTC.MaxConnectionsToServer = "100"

Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache $DLTC

Restart-Service -Name AppFabricCachingService

These settings can only be changed using PowerShell and must be run on all the distributed cache servers in the cluster. This will virtually eliminate the cache timeout issues.

Step 2

Modify the Security Token Service cache settings by using PowerShell to run the following:

$sts = Get-SPSecurityTokenServiceConfig

$sts.MaxServiceTokenCacheItems = "1500"

$sts.MaxLogonTokenCacheItems = "1500"

$sts.Update()

This will also need to be run on all the distributed cache servers.

Step 3

Download and install the latest AppFabric CU from Microsoft. This will need to be installed on all the servers in the farm that are hosting Distributed Cache.  

Step 4

Modify the DistributedCacheService.exe.config file on all servers to fix the issue with the background garbage collection process. This file can be found in the \Windows\System32\AppFabric folder. Add the following line to the config file between the </configSections> tag and the <dataCacheConfig> tag.

<appSettings><add key="backgroundGC" value="true"/></appSettings>

Step 5

Restart the AppFabric Windows service and the Distributed Cache SharePoint service and run an IISRESET on all machines. I prefer to do a full farm reboot just to be safe and to avoid having to restart the services manually on each server. Depending on the number of servers in the environment, this can be a big time-saver.

This should fix the issues and clear up the errors filling up ULS.

I have created a couple basic scripts for making the token cache changes. I would recommend saving the PowerShell commands in step 1 and step 2 as scripts to use in your own environments. These will save a good bit of time compared to making all the changes manually. I am also working on a script to make the changes to the Distributed Cache config file. Once I have this completed I will add it to the instructions

Conclusion:

It’s important to keep up with updates to all of the Microsoft technologies that are incorporated within SharePoint Administration. Occasionally, Microsoft will find a bug in a previously released version of one of these technologies and the sooner it is addressed the better. These bugs can be anywhere on the spectrum from simple functionality tweaks to serious security vulnerabilities. Although this particular bug was resolved with AppFabric CU5, it is highly recommended to stay up to date with all of the current MS updates. At the time this article was published, the current AppFabric CU available is CU8. It can be downloaded here: https://www.microsoft.com/en-us/download/details.aspx?id=54440 . Following the instructions in this blog and staying up to date with all of the AppFabric CUs will keep your Distributed Cache implementation functioning at a high level and will eliminate the flood of errors that can show up in ULS and the event logs.

By IncWorx Team 04 Oct, 2017

If you’re like many companies looking at migrating some or all of your on-premises SharePoint footprint to SharePoint Online then you undoubtedly have realized it’s not as simple as saying a few magic words and ‘voila’, all your sites and content have been transformed into the cloud.

There are a several planning steps that should be performed to minimize the challenges and headaches post-migration. Let’s go over ‘4 Planning Steps to a Successful SharePoint Online Migration’.

In future blog posts, we’ll dive technically deeper into tools, scripts, or processes that can be used to simplify each step.


By IncWorx Team 22 Sep, 2017

If you are implementing SharePoint in your organization for the first time, or you are planning to upgrade your current SharePoint environment, you have likely questioned whether to use Office 365 and SharePoint Online versus an on-premises installation of SharePoint Server. To make the decision easier, below are five important factors to consider:

By IncWorx Team 16 Aug, 2017
Learn how to analyze data with SharePoint and Infopath using Power BI or Power Query in this step by step instructional post.
By IncWorx Team 27 Jul, 2017

SharePoint support isn’t only about fixing something that's broken, in fact, it is more about pro-active monitoring, training, development, and demonstrating how to use SharePoint. When you connect with a partner that provides a holistic approach to support, you will see what a big difference it can make. SharePoint Support should be available when you need it most or when you just have a quick question. With the right support your organization can benefit immediately.  Here are 5 major signs you are in need of expert SharePoint support services:

1. Still sending attachments by email? This very popular way of sharing documents, while familiar, is no longer considered a good practice and with SharePoint sharing and collaborating on documents is a powerful core feature, making sending documents by email a thing of the past.

2. Feeling like you’re on an island?  In many organizations there is that one person you can count on to answer your technical questions, but what happens when that person isn’t available or doesn’t exist?

3. Is time really money? when your time is being spent trouble shooting technology or trying to figure out how to use SharePoint what are you gaining? You are valuable for the role you play in your organization, technologies like SharePoint exist to support and increase your value not slow you down.

4. Are you using SharePoint like a shared drive? Similar to sending emails as attachments, using SharePoint like a shared drive also remains popular. Making folders to organize documents is the way things used to get done, with a little training and support the powerful document management capabilities built into SharePoint will take document management and sharing to the next level.

5. How do I...? With any new technology, we all feel a little lost. Grasping the concept of SharePoint can be a challenge, but once you figure it out the opportunities to create value for you, your team and your organization are endless but how do you get there?


By IncWorx Team 27 Jul, 2017