Configure SharePoint managed metadata columns using PowerShell CSOM

I received the request from a colleague to create a script that will configure all managed metadata columns in SharePoint Online to allow people to fill in values.
My colleague first tried this using PnP but was unable to configure the necessary property of a managed metadata column.
It is possible to set this property using the client object model (CSOM) in PowerShell.
You will need the SharePoint Online Client Components SDK which you can download at https://www.microsoft.com/en-us/download/confirmation.aspx?id=42038

We first verified that we were able to change this property by using the below script:

$url = "https://<TenantName>.sharepoint.com"
$userName = "admin@<TenantName>.onmicrosoft.com"
$password = Read-Host "Please enter the password for $($userName)" -AsSecureString

Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"

$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)

$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$context.Credentials = $SPOcredentials
$web = $context.Web
$context.Load($web)
$list = $web.lists.GetByTitle("Documenten")
$context.Load($list)
$field = $list.fields.getbytitle("Zoekwoorden")

$context.load($field)
$context.ExecuteQuery()

$taxField = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($context, $field)

$taxfield.open = $true
$taxfield.update()

$context.executequery()

Once we retrieved the correct field we had to cast this to a taxonomyField to be able to set the property “Open”.
The next step was to build a script around this that allows us to configure all managed metadata columns on the rootsite and all subsites.
This script has been upload to GitHub: https://github.com/peetersm12/ConfigureManagedMetadaColumnCSOM

The script will loop through all subsites to find the specified column on all the lists and libraries available.
You can first use a “preview” action to find all lists and libraries which have a column with the name you are looking to update.
Then you can update these columns so that users are allowed to fill in values.
Note that you can use this script for all updates for a specific column, just change the part where you  find the above code.

Using the script

Open the .ps1 file and copy the whole content of the file to preload the functions in the SharePoint Online Management Shell as administrator.

Next run 1 of the following commands:

To first list all lists/libraries which currently has the specified column title
set-mmcolumn -Action “Preview”

To update all lists and libraries which has the specified column title
set-mmcolumn -Action “Update”

Running the preview

Run the following command:

set-mmcolumn -Action "Preview"

and answer the following questions 1 by 1

The script will start and the output will be shown on screen, you can also verify the transcript although this isn’t color coded but search for “Found:”

We can see that our column has been found for the library “Documenten” and users are currently not allowed to fill in values.
Next run the script to update these columns.

Running the update

Run the following command:

set-mmcolumn -Action "Update"

and enter the following questions 1 by 1

The script will start and the output will be shown on screen, you can also verify the transcript although this isn’t color coded but search for “Found:”


We can see that our column has been found for the library “Documenten” and the value has been updated from False to true.
Run the preview again to see if all “green lines” are now set to true

DestinationType is a duplicate attribute name while editing Nintex Workflow

We encountered an issue where some Nintex Workflow actions weren’t editable anymore. The error was saying “Sorry, something went wrong” while opening for example the “Create item” action and the ULS was saying “DestinationType is a duplicate attribute name”.

The following full message was fount in the ULS logs

System.Xml.XmlException: ‘DestinationType’ is a duplicate attribute name. Line 1, position 163.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.AttributeDuplCheck()
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at Nintex.Workflow.Activities.Adapters.WssActions.WssActionsFile.GetCoercionsXmlStringForJavaScript()
at Nintex.Workflow.ApplicationPages.Activities.ContextDataLookup.BuildClientScript()
at Nintex.Workflow.ApplicationPages.Activities.ContextDataLookup.Page_Load(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

We tried the following things to resolve this issue (with no effect):

  1. IISReset
  2. Restarting the SharePoint Timer Service
  3. Clearing the cache folder
  4. Restart the SharePoint Timer Service

We were only able to edit the action again after restarting all SharePoint servers in the farm.

 

The OOTB approval workflow could not update the item in SharePoint

We encountered the issue where the OOTB approval workflow stopped with the error message “The workflow could not update the item, possibly because one or more columns for the item require a different type of information”.

There are a few possible solutions for this issue.

  1. Content approval is not configured for the library
  2. The service account used by the workflow is disabled/removed or password expired as the workflow updates the item with this account
    You can republish the worfklow with an account that has sufficient permissions for the library but who is also working.

The previous version of the workflow has been started a few times before we could resolve this issue where you can use the below script to retrieve the items where the previous version of the workflow is current in progress. First find the workflow name by going to the workflow settings on the specific library.

Next run the following script in the SharePoint Management Shell as administrator where you will need to add the web url, list title and previous version date.

$web = get-spweb <SiteUrl>
$list = $web.lists.trygetlist("<ListName>")
$items = $list.Items
Foreach($item in $items){
$workflows = $item.workflows
foreach($workflow in $workflows){
if($workflow.statustext –eq "In Progress" –or $workflow.statustext –eq "Error Occurred"){
$result = $item.workflows.parentassociation
If($result.internalname –like "*Previous Version:9-2-2018 18:46:48*"){
write-host "$($item.name)"
}
}
}
}

and you will receive a list of the items for which this workflow is still “In Progress” or if an “Error Occurred”