Sunday, 14 February 2021

Document library item view/edit properties screen populates blank screen in SharePoint Online

Recently we have migrated SharePoint 2010 site to SharePoint Online and after the migration we noticed an issue in some of the doc libraries. Contents can be uploaded, but the prompt to fill out properties is not happening and when selecting to edit properties, the fields to populate/amend is not appearing. Edit shows as a blank screen. See this below screen.



We have changed the view from modern to classic list view where I can see all the fields but was not able to update the item due to 'Copy Source' field which is OOTB column.


The root cause is the read only column "Copy Source" being added to the list's content type "Document". Removing the field from content type, classic view starts working. However in modern view still prompts the blank screen.

We fixed the issue in Modern UI by removing below fields from Document Content Type using PowerShell script.

like wise we have the same issue with Picture library, Custom list, Links list as well. 

Below is the script which will remove the read-only fields from content types: Document, Link, Item and Picture from the associated library/list.

Note: OOTB field IDs are unique for all the lists/libraries in site collection.

#Load SharePoint CSOM Assemblies
Add-Type -Path "F:\microsoft.sharepointonline.csom.16.1.8412.1200\lib\net45\Microsoft.SharePoint.Client.dll"
Add-Type -Path "F:\microsoft.sharepointonline.csom.16.1.8412.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "F:\microsoft.sharepointonline.csom.16.1.8412.1200\lib\net45\Microsoft.SharePoint.Client.Taxonomy.dll"

Try
{
$WebURL="https://tenant.sharepoint.com/sites/ProjectSites/PC0296/"

$UserName="liakathali.mohammed@domain.com"
$Password ='XXXXXXXXX'

$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($WebURL)
$Ctx.Credentials = $Credentials
$Ctx.ExecuteQuery()

#Get Lists from the web
$Ctx.Load($Ctx.Web.Lists)
$Ctx.executeQuery()

#Impacted content types
$ContentTypeName="Document"
$ContentTypeName1="Link"
$ContentTypeName2="Picture"
$ContentTypeName3="Item"

#Get Lists from the web
$Lists = $Ctx.Web.Lists
$Ctx.Load($Lists)
$Ctx.ExecuteQuery()

#Loop through each document library and Get the Title
    Foreach ($list in $Lists)
    {
    Write-host $list.Title
      if(($list.Title -eq "Correspondence") -or ($list.Title -eq "Supporting Documentation") -or ($list.Title -eq "Project Plan"))
      {
        #Get contenttype from list
         $ctypecoll = $list.ContentTypes #| Where {$_.Name -Match $ContentTypeName} #-ErrorAction SilentlyContinue
         $Ctx.Load($ctypecoll)  
         $Ctx.ExecuteQuery()
         $ctypecoll.Name
 
        #Check if the content type exists in the list      
         $ContentType = $ctypecoll | Where {$_.Name -eq $ContentTypeName}
         If($ContentType -eq $Null)
         {
             Write-host "Content Type '$ContentTypeName' doesn't exists in '$list'" -f Yellow
             Return
         }

        write-host -f Green "Content Type ID:" $ContentType.Name
        write-host -f Green "Content Type ID:" $ContentType.Id

        #Get the column to delete from content type
         $ContentTypeFieldColl =  $ContentType.Fields
         $Ctx.Load($ContentTypeFieldColl)
         $Ctx.ExecuteQuery()
        
         #Get the field link from content type
         $FieldLinkColl = $ContentType.FieldLinks
         $Ctx.Load($FieldLinkColl)
         $Ctx.ExecuteQuery()

        #Get Author Field
         $author = $FieldLinkColl.GetById('1df5e554-ec7e-46a6-901d-d85a3881cb18')
         $Ctx.Load($author)
         $Ctx.ExecuteQuery()
         write-host $author.Name
         $author.DisplayName
 
         #Get Editor Field
         $editor = $FieldLinkColl.GetById('d31655d1-1d5b-4511-95a1-7a09e9b75bf2')
         $Ctx.Load($editor)
         $Ctx.ExecuteQuery()
         write-host $editor.Name 

         #Get Copy Source Field
         $copysource = $FieldLinkColl.GetById('6b4e226d-3d88-4a36-808d-a129bf52bccf')
         $Ctx.Load($copysource)
         $Ctx.ExecuteQuery()
         write-host $copysource.Name

         #Get Checked Out To Field
         $checkedoutto = $FieldLinkColl.GetById('3881510a-4e4a-4ee8-b102-8ee8e2d0dd4b')
         $Ctx.Load($checkedoutto)
         $Ctx.ExecuteQuery()
         write-host $checkedoutto.Name 

         $author.DeleteObject()
         $editor.DeleteObject()
         $copysource.DeleteObject()
         $checkedoutto.DeleteObject()
         $ContentType.Update($false)
         $ctx.ExecuteQuery()

         Write-host "Columns" $author.Name "," $editor.Name "," $copysource.Name "," $checkedoutto.Name "Deleted from list:" $list.Title "Successfully!" -ForegroundColor Green
       }

      elseif ($list.Title -eq "Photos")
      {
       #Get contenttype from list
        $ctypecoll = $list.ContentTypes
        $Ctx.Load($ctypecoll)  
        $Ctx.ExecuteQuery()
        $ctypecoll.Name 

       #Check if the content type exists in the list      
         $ContentType = $ctypecoll | Where {$_.Name -eq $ContentTypeName2}
         If($ContentType -eq $Null)
         {
             Write-host "Content Type '$ContentTypeName2' doesn't exists in '$list'" -f Yellow
             Return
         }
        write-host -f Green "Content Type ID:" $ContentType.Id

        #Get the column to delete from content type
         $ContentTypeFieldColl =  $ContentType.Fields
         $Ctx.Load($ContentTypeFieldColl)
         $Ctx.ExecuteQuery() 

        #Get the field link from content type
         $FieldLinkColl = $ContentType.FieldLinks
         $Ctx.Load($FieldLinkColl) 

        #Get Author Field
         $author = $FieldLinkColl.GetById('1df5e554-ec7e-46a6-901d-d85a3881cb18')
         $Ctx.Load($author)
         $Ctx.ExecuteQuery()
         write-host $author.Name 

         #Get Editor Field
         $editor = $FieldLinkColl.GetById('d31655d1-1d5b-4511-95a1-7a09e9b75bf2')
         $Ctx.Load($editor)
         $Ctx.ExecuteQuery()
         write-host $editor.Name 

         #Get Copy Source Field
         $copysource = $FieldLinkColl.GetById('6b4e226d-3d88-4a36-808d-a129bf52bccf')
         $Ctx.Load($copysource)
         $Ctx.ExecuteQuery()
         write-host $copysource.Name 

         #Get Checked Out To Field
         $checkedoutto = $FieldLinkColl.GetById('3881510a-4e4a-4ee8-b102-8ee8e2d0dd4b')
         $Ctx.Load($checkedoutto)
         $Ctx.ExecuteQuery()
         write-host $checkedoutto.Name 

         $author.DeleteObject()
         $editor.DeleteObject()
         $copysource.DeleteObject()
         $checkedoutto.DeleteObject()
         $ContentType.Update($false)
         $Ctx.ExecuteQuery()
         Write-host "Columns" $author.Name "," $editor.Name "," $copysource.Name "," $checkedoutto.Name "Deleted from list:" $list.Title "Successfully!" -ForegroundColor Green
      } 

      elseif ($list.Title -eq "Helpful Links")
      {
       #Get contenttype from list
        $ctypecoll = $list.ContentTypes
        $Ctx.Load($ctypecoll)  
        $Ctx.ExecuteQuery()
        $ctypecoll.Name 

       #Check if the content type exists in the list      
         $ContentType = $ctypecoll | Where {$_.Name -eq $ContentTypeName1}
         If($ContentType -eq $Null)
         {
             Write-host "Content Type '$ContentTypeName1' doesn't exists in '$list'" -f Yellow
             Return
         }
        write-host -f Green "Content Type ID:" $ContentType.Id

        #Get the column to delete from content type
         $ContentTypeFieldColl =  $ContentType.Fields
         $Ctx.Load($ContentTypeFieldColl)
         $Ctx.ExecuteQuery()

        #Get the field link from content type
         $FieldLinkColl = $ContentType.FieldLinks
         $Ctx.Load($FieldLinkColl) 

        #Get Author Field
         $author = $FieldLinkColl.GetById('1df5e554-ec7e-46a6-901d-d85a3881cb18')
         $Ctx.Load($author)
         $Ctx.ExecuteQuery()
         write-host $author.Name 

         #Get Editor Field
         $editor = $FieldLinkColl.GetById('d31655d1-1d5b-4511-95a1-7a09e9b75bf2')
         $Ctx.Load($editor)
         $Ctx.ExecuteQuery()
         write-host $editor.Name 

         $author.DeleteObject()
         $editor.DeleteObject()
         $ContentType.Update($false)
         $ctx.ExecuteQuery()
         Write-host "Columns" $author.Name "," $editor.Name "Deleted from list:" $list.Title "Successfully!" -ForegroundColor Green
      }

      elseif ($list.Title -eq "Custom List")
      {
       #Get contenttype from list
        $ctypecoll = $list.ContentTypes
        $Ctx.Load($ctypecoll)  
        $Ctx.ExecuteQuery()
        $ctypecoll.Name 

        #Check if the content type exists in the list      
         $ContentType = $ctypecoll | Where {$_.Name -eq $ContentTypeName3}
         If($ContentType -eq $Null)
         {
             Write-host "Content Type '$ContentTypeName3' doesn't exists in '$list'" -f Yellow
             Return
         }
        write-host -f Green "Content Type ID:" $ContentType.Id 

        #Get the column to delete from content type
         $ContentTypeFieldColl =  $ContentType.Fields
         $Ctx.Load($ContentTypeFieldColl)
         $Ctx.ExecuteQuery()

        #Get the field link from content type
         $FieldLinkColl = $ContentType.FieldLinks
         $Ctx.Load($FieldLinkColl)

        #Get Author Field
        $author = $FieldLinkColl.GetById('1df5e554-ec7e-46a6-901d-d85a3881cb18')
         $Ctx.Load($author)
         $Ctx.ExecuteQuery()
         write-host $author.Name 

         #Get Editor Field
         $editor = $FieldLinkColl.GetById('d31655d1-1d5b-4511-95a1-7a09e9b75bf2')
         $Ctx.Load($editor)
         $Ctx.ExecuteQuery()
         write-host $editor.Name 

         $author.DeleteObject()
         $editor.DeleteObject()
         $ContentType.Update($false)
         $ctx.ExecuteQuery()
         Write-host "Columns" $author.Name "," $editor.Name "Deleted from list:" $list.Title "Successfully!" -ForegroundColor Green
      }
    }
   }
    Catch {

         write-host -f Red "Error Deleting Column from Content Type!" $_.Exception.Message
     }

Friday, 12 February 2021

Coercion Failed: Input cannot be null for this coercion in SharePoint Online list

We have list workflow configured in our SharePoint Online site, to send email on list item created. However our workflow is keep failing and it's getting cancelled with the below error message which we found on workflow history for the particular workflow instance.

Coercion Failed: Input cannot be null for this coercion


Root Cause:

When we look at email body, we noticed a multiple selection field which is causing the issue and it is set to return as "Choices, Comma Delimited" value. Whenever this field value returns null, then our workflow gets cancelled with the above error. (I used 'log to workflow history' action to verify the values)

Solution:

To fix this issue we have changed the return type for the field from "Choices, Comma Delimited" to "As String" and then workflow started working without any error.