I am new to SharePoint 2013 and am not a coder.
I have a List, "IRM Summary", that contains
- Date Opened,
- Date Closed
- Days Open and
- Today columns.
If there is a
Date Closed date, then Days Open = Date Closed-Days Open.
Else
Days Open = Today-Date Created.
This is working fine except that in SharePoint 2013, as I've found out, Today needs to be updated via a script and nightly scheduled task.
I've found the code below online (and several variations of it) and have adapted the names to our environment.
Start-SPAssignment -Global
$web = Get-SPWeb http://mysite/sites/IRM
$list = $web.Lists[“IRM Summary”]
$list.Items | ForEach-Object {
$_[“Today”] = [System.DateTime]
$_.SystemUpdate($false)
$list.Update()
}
$web.Dispose()
Stop-SPAssignment -Global
However, when I run it in SharePoint 2013 Management Shell, I get the following errors:
Cannot index into a null array. At C:\SPListItemsWithTodaysDate.ps1:26 char:1 + $_["Today"] = [System.DateTime] #Replace TodaysDate with your field name + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray
You cannot call a method on a null-valued expression. At C:\SPListItemsWithTodaysDate.ps1:27 char:1 + $_.SystemUpdate($false) + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression. At C:\SPListItemsWithTodaysDate.ps1:28 char:1 + $list.Update() + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
The list itself is populated, and currently there are values in the Today column for every row in the list.
Any help would be appreciated, either with "fixing" the script or using another (non-Javascript) solution or workaround.
"
-symbols with“
”
, which are not converted to default quotation marks when ran in command line.