April 26, 2018

SharePoint: Setting person field default values in “Column default value settings”

Problem

SharePoint doesn’t allow setting person field default values in “Column default value settings” of a list, in fact, it doesn’t even show the person type fields in the “Column default value settings” screen.

Solution

Using browser, you cannot do it, but modifying /yourlist/forms/client_LocationBasedDefaults.html using SharePoint Designer or programmatically makes it possible. Just put in the full user identity claim, below sample is from SharePoint Online.

<DefaultValue FieldName="MyPersonFieldName">i:0#.f|membership|firstname.lastname@mydomain.onmicrosoft.com</DefaultValue>

SharePoint: Multiple default values using “Column default value settings”

Problem

SharePoint doesn’t allow selecting multiple default values in “Column default value settings” of a list, even though the column in question is choice and allowing multiselect.

Solution

Using browser, you cannot do it, but modifying /yourlist/forms/client_LocationBasedDefaults.html using SharePoint Designer or programmatically makes it possible. Just use format ;#CHOICE1;#CHOICE2;#, e.g.,

<DefaultValue FieldName="MyMultiChoiceFieldName">;#Valintatalo;#Citymarket;#</DefaultValue>

SharePoint: Setting list field default and calculated values using PnP JS

Question

How to set list field default and calculated values using PnP JavaScript?

Solution

For default values:

list.fields.getByTitle("ProjectName").update({ DefaultValue: "some default value"});

For calculated values:

list.fields.getByTitle("ProjectName").update({ DefaultValue: "=\";#choice a;#choice b;#\""});

For calculated values it looks a bit nasty on SharePoint Online modern libraries, but filtering seems to work, as well as modifying choice selection. It looks and works nicely on classic side, although default value selection remains on Choice radio button.

Classic
imageimage
Modern
image

April 23, 2018

SharePoint: Yet another reason for ‘The issuer of the token is not a trusted issuer’

Problem

Was creating custom STS, and no matter what I did, I always got the very common ‘The issuer of the token is not a trusted issuer’ error after successfully authenticating and getting redirected back to SharePoint.

Full error:

Application error when access /sites/somesite/_layouts/15/Authenticate.aspx, Error=The issuer of the token is not a trusted issuer. 
  at Microsoft.SharePoint.IdentityModel.SPLocalIssuerNameRegistry.GetIssuerName(SecurityToken securityToken, String requestedIssuerName)   
  at Microsoft.IdentityModel.Tokens.Saml11.Saml11SecurityTokenHandler.CreateClaims(SamlSecurityToken samlSecurityToken)   
  at Microsoft.IdentityModel.Tokens.Saml11.Saml11SecurityTokenHandler.ValidateToken(SecurityToken token)   
  at Microsoft.IdentityModel.Tokens.SecurityTokenHandlerCollection.ValidateToken(SecurityToken token)   
  at Microsoft.IdentityModel.Web.TokenReceiver.AuthenticateToken(SecurityToken token, Boolean ensureBearerToken, String endpointUri)   
  at Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequest request)   
  at Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args)   
  at Microsoft.SharePoint.IdentityModel.SPFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs)   
  at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Solution

Or one of the many solutions to this generic error was to redirect users to correct address in SharePoint after authentication. In my code, the scope.ReplyToAddress ended up being something like

/sites/somesite/_layouts/15/Authenticate.aspx?Source=/sites/somesite.

which was obviously wrong, as replies need to go the /_trust/, so instead using

/_trust/default.aspx

as reply address fixed the issue.

And, when we’re talking of SharePoint, it doesn’t automatically include the wreply parameter in authentication flow, so enable that in your Trusted Identity Token Issuer properties like this:

$ap = Get-SPTrustedIdentityTokenIssuer -Identity "STS-Dev"
$ap.UseWReplyParameter=$true
$ap.Update()

So finally in your custom STS GetScope method, you can just do:

scope.ReplyToAddress = request.ReplyTo;

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()
}