I'm struggeling with setting the default value of ArticleStartDate
date-time column using PowerShell and CSOM.
Bakground: I have a content type, used by a page layout, inheriting from Article Page
and hence inherits the ArticleStartDate
field.
What I want to achieve is setting the default date of this column to [Today]
, globally, or only on one pages list (it really doesn't matter on what level the default values is set).
I have tried numerous variants like
$ctx = Get-SPOContext
$list = Get-SPOList -Identity "Pages"
$ctx.Load($list.Fields)
$ctx.ExecuteQuery()
$articleDateField = $list.Fields | where {$_.InternalName -eq "ArticleStartDate" }
$articleDateField = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.FieldDateTime]).Invoke($ctx, $articleDateField)
$articleDateField.DefaultValue = "[Today]";
$articleDateField.UpdateAndPushChanges($true)
$ctx.ExecuteQuery()
Or the simpler
$ctx = Get-SPOContext
$list = Get-SPOList -Identity "Pages"
$ctx.Load($list.Fields)
$ctx.ExecuteQuery()
$articleDateField = $list.Fields | where {$_.InternalName -eq "ArticleStartDate" }
$articleDateField.DefaultValue = "[Today]";
$articleDateField.Update()
$ctx.ExecuteQuery()
In neither of the cases I am getting any error messages, but when I retrieve the field again, the default value is not set.
I have noticed that the field is marked as Sealed=TRUE
on site level, is this the problem? And if so, can we change that using CSOM or am I stuck?