March 22, 2018

Adding divider when programmatically creating Office UI Fabric IContextualMenuItem[]

Question

When declaratively creating Context menu items, you can add divider using

  <li class="ms-ContextualMenu-item ms-ContextualMenu-item--divider"></li>

How to add it when programmatically creating array of IContextualMenuItems?

Solution

Use itemType: ContextualMenuItemType.Divider, like this

const items: IContextualMenuItem[] = [];
items.push( {
    key: "divider1",
    itemType: ContextualMenuItemType.Divider
} );

February 14, 2018

Azure B2C: Cannot delete directory due to ProxyIdentityExperienceFramework

Problem

I wanted to delete my testing Azure B2C directory, and followed steps to remove it at here and here. However, attempting to delete the directory, indicated that there was some app registrations preventing the deletion.

2

Clicking on the Required Action, I could see the Native ProxyIdentityExperienceFramework still existed. WHen I went ahead to delete it, I found out that the Delete button was disabled.

1

This app was created as part of configuring Azure B2C to use custom policies, as described here. App wasn’t a “converged app”, so it wasn’t visible in the Microsoft Application Console in order to delete it, as some suggested. I had also emptied the application of any Redirect URIs, Owners, Required permissions. Still the Delete button remained disabled.

Solution

  1. Go to Azure B2C tenant
  2. Click Azure Active Directory on left menu
  3. Click App registrations
  4. Select All apps from filter drop-down
  5. Select the ProxyIdentityExperienceFramework app
    3
  6. Select Manifest
  7. Change availableToOtherTenants to false
    4
  8. Click Save
  9. Click Delete to delete the app

January 25, 2018

Disable friendly formatting on date columns on SharePoint site collection

Problem

After migrating content to SharePoint 2016, all date columns were in Friendly display format. I needed a neat way to update them across the site collection using PowerShell, but all scripts that attempted to modify the FriendlyDisplayFormat property of a column had some issues.

This one on Social Technet didn’t work as our site wasn’t in English, nor did this or this. Some looked alright, but threw error “The property 'FriendlyDisplayFormat' cannot be found on this object. Verify that the property exists and can be set.

Solution

$WebCollection = Get-SPSite "<SITEURL>" -Limit All | Get-SPWeb -Limit All
 
foreach($web in $WebCollection)
{
     Write-Host "Connected to "$web.Title -ForegroundColor Yellow

    $lists = $web.Lists
 
     foreach($list in @($lists))
     {
         Write-Host "Connected to ...$list" -ForegroundColor Yellow
        
         foreach($field in @($list.Fields))
         {      
             $column = $list.Fields.GetFieldByInternalName($field.InternalName)
       
             if($column.Type -eq "DateTime")
             {                  
                 Write-Host "Connected to ......"$column.Title -ForegroundColor Yellow
                 $column.FriendlyDisplayFormat = 1
                 $column.update()               
             }
         }
     }

    $web.Dispose()
}

January 18, 2018

SharePoint app: ‘An error occurred while processing your request’ on Windows 7 and IE11

Problem

When deploying a provider hosted app for SharePoint (Online), and you have a button on the app causing normal ASP.NET postback, whenever clicking on the button, you get error “An error occurred while processing your request.”

What is interesting is that the issue only occurs on IE11 on Windows 7. It doesn’t occur on IE11 on Windows 10, for example.

Thoughts

When debugging the SharePoint app at the time of clicking the button and postback, I saw that contrary to when entering the form with Windows7+IE11, there was a SPAppToken Form parameter, but on postback it was gone. Some people had solved it by manually taking the SPAppToken parameter and placing it into a hidden field on the page in order to ensure it was there also during postback.

Solution

I finally figured out solution, which didn’t involve any changes in the program code. On IE11 on Windows 7, you need to add the URL of the provider host app into Trusted Sites in IE11.

If app is hosted in Azure, the URL could be something like https://myproviderhostedapp.azurewebsites.net.

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.