December 14, 2017

Chart.js Stacked 100% plugin with Mixed chart

Problem

I was working with HappyOrNot API, and needed to display charts on SharePoint Online. One of the charts you have on HappyOrNot portal is a mixed chart with stacked bars and line, like this

hon1

I had earlier used Flot for my charting needs, but this time Chart.js seemed more appropriate. I soon, however found out that it doesn’t have built-in support for 100% height stacked charts, so my charts ended up looking like this.

hon2

Then I found a nice 100% stacked bar chart plugin for Chart.js and enabled it, still not good, now it took all datasets and calculated relative heights including the line dataset as well.

hon3

Time to modify plugin source code.

Solution

To make the story short, I just needed to ignore the specific dataset (line) from the relative height calculation.

First of all, add the following option to the line chart yAxes: stacked: false. This is used in the plugin code to determine not to set the min/max values to 0 and 100 respectively. My plugin modification also relies for the line dataset to have property type: ‘line’.

Modifying the index.js of the plugin by adding few small changes did the trick. You can view changes here.

Am I HappyOrNot with the end result? Definitely happy!

hon4

December 11, 2017

SharePoint Online: Hide content type on list

Task

Hide Content type on SharePoint Online document library.

Solution

Requires PnP-Powershell, installation instructions here.

Connect-PnPOnline –Url “https://tenant.sharepoint.com”
$ctx = Get-PnPContext

$web = Get-PnPWeb

$doclib = Get-PnPList -Identity "<DOCLIBNAME>" -Includes ContentTypes,RootFolder.UniqueContentTypeOrder

$rootFolder = $doclib.RootFolder

$ct = $doclib.ContentTypes | where {$_.Name -eq "<CT TO BE HIDDEN>"}
$ct2 = $doclib.ContentTypes | where {$_.Name -eq "<CT TO BE HIDDEN, USUALLY FOLDER>"}

if($rootFolder.UniqueContentTypeOrder -eq $null)
{
     $contentTypesInPlace = New-Object -TypeName 'System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]'

    #$contentTypesInPlace = $doclib.ContentTypes | where {$_.Id -ne $ct.Id}
     foreach($ct in $doclib.ContentTypes | where {$_.Id -ne $ct.Id -and $_.Id -ne $ct2.Id})
     {
         $contentTypesInPlace.Add($ct.Id)
     }
}
else
{           
     $contentTypesInPlace = [System.Collections.ArrayList] $rootFolder.UniqueContentTypeOrder
     $contentTypesInPlace = $contentTypesInPlace | where {$_.StringValue -ne $ct.Id}
}
         
#Set the UniqueContentTypeOrder to the collection we made above
$rootFolder.UniqueContentTypeOrder = [System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]] $contentTypesInPlace
         
#Update the root folder
$rootFolder.Update()               
Execute-PnPQuery

November 13, 2017

Azure Stream Analytics job Query IoTHub.ConnectionDeviceId null

Problem

Having connected Azure Stream Analytics job to IoT Hub, and trying to get hold of IoTHub.ConnectionDeviceId in the Stream Analytics job Query, you just get NULL value. Several instructions on the net just say that query such as below should return the device id, but no.

SELECT IoTHub.ConnectionDeviceId AS DeviceId
INTO SQL
FROM IoTHub TIMESTAMP BY EntryTime

Posts such as this almost made me open a support ticket as I was suspecting some platform related issue.

Solution

This one was rather trivial once I used SELECT * to find out what is really coming from the IoTHub, so changing the query to

SELECT IoTHub.IoTHub.ConnectionDeviceId

will do the trick and you can get hold of the Device ID without explicitly passing it from the IoT device to IoT Hub.

And further searching got me to this article that has clear example with query such as in my example.

August 1, 2017

UNMS on Azure

Below are the bare minimum steps to install Ubiquiti’s Network Management System on a Docker container on Azure Ubuntu VM. After adding my ER-X-SFP v 1.9.7 to UNMS, I can now see it on the UNMS console.

  1. Create new VM "Docker on Ubuntu Server"
  2. clip_image001

    1. For VM Size, I used Basic A1, which nearly corresponds with the requirements for RAM (1.75GB vs 2 GB)
  3. Connect to VM using Putty
    1. Username and pwd are the ones you typed in when creating the VM
  4. Update Ubuntu to 16.04.1 (or newer)
  5. $ sudo apt-get update
    $ sudo apt-get dist-upgrade

  6. To check upgrade succeeded, run
  7. $ lsb_release -a

  8. According to UNMS installation steps at https://github.com/Ubiquiti-App/UNMS/wiki/Installation-%26-Update run commands
  9. $ curl -fsSL https://raw.githubusercontent.com/Ubiquiti-App/UNMS/master/install.sh > /tmp/unms_install.sh && sudo bash /tmp/unms_install.sh

  10. Add HTTP endpoint to Azure VM, optionally allowing it only from your IP address
  11. Connect to UNMS using browser at http://xyz.cloudapp.net
  12. In UNMS Settings, I changed the “Ping Address” to ping.ubnt.com as suggested at https://community.ubnt.com/t5/UNMS-Ubiquiti-Network-Management/ICMP-blocked-to-UNMS-in-Azure/m-p/2007979#M219

Optional modifications

In addition I changed UNMS Inform port using the following command, and added endpoint to Azure to allow it from my home IP.

$ sudo bash /tmp/unms_install.sh --ws-port 8444

I also added CNAME to my DNS provider to access UNMS using my my own domain name. In UNMS settings at Settings –> UNMS I added this custom domain name unms.mydomain.com to “UNMS Hostname/IP”.

 

May 2, 2017

Office Online Server on Windows Server 2016: 'InkandHandwritingServices' was not found

Problem

When installing Office Online Server on Windows Server 2016, and using the Add-WindowsFeature script provided on all of the installation instruction articles, such as this, you will get error

Add-WindowsFeature : ArgumentNotValid: The role, role service, or feature name is not valid: 'InkandHandwritingServices'. The name was not found.

Solution

Windows Server 2016 doesn’t contain Ink And Handwriting Services, so omit that from the Add-WindowsFeature command. So, working script for WS2016 is:

Add-WindowsFeature Web-Server,Web-Mgmt-Tools,Web-Mgmt-Console,Web-WebServer,Web-Common-Http,Web-Default-Doc,Web-Static-Content,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Security,Web-Filtering,Web-Windows-Auth,Web-App-Dev,Web-Net-Ext45,Web-Asp-Net45,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Includes,NET-Framework-Features,NET-Framework-Core,NET-HTTP-Activation,NET-Non-HTTP-Activ,NET-WCF-HTTP-Activation45

March 31, 2017

SharePoint: Workaround for Script Editor and Chrome ERR_BLOCKED_BY_XSS_AUDITOR

Problem

In recent Chrome browser, it has become little annoying to work with SharePoint tool due to Chrome throwing ERR_BLOCKED_BY_XSS_AUDITOR error when working with the Script Editor web part. This is due to XSS auditor on Chrome blocking JavaScript included in the Script Editor Web Part. Issue occurs on SharePoint Online and on-premises SharePoint 2016 and 2013 and occurs regardless if site is accessed via HTTP or HTTPS.

Steps to repro:
  1. On SharePoint publishing page, add Script Editor web part to content area or web part zone
  2. Add the following code to the web part (any JS will do the trick): 

    <script>
    console.log("asd")
    </script>

  3. Click Insert at the bottom of the Script Editor content dialog
    --> Chrome throws you to page saying


    This page isn’t working

    Chrome detected unusual code on this page and blocked it to protect your personal information (for example, passwords, phone numbers, and credit cards).
    • Try visiting the site's homepage.
    ERR_BLOCKED_BY_XSS_AUDITOR

Workaround

You can disable the XSS Auditor by appending the following value to web.config on your on-premises SharePoint 2013 or 2016 web site.

  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-XSS-Protection" value="0" />
      </customHeaders>

For SharePoint Online, there is no workaround at the moment.