vendredi 20 février 2015

How to get and set column from type "number" by powershell



I am using sp 2010. I have a library with documents. There is a column "CalcultatedWeekNumber" from type "Calculated". I have another column Week from type "Number". I try to get the value of the calculated field and set it on the column week:



$site = new-object Microsoft.SharePoint.SPSite("http://ift.tt/1AThS51")
$web = $site.openweb()
$list = $web.Lists["BMRSoproTest"]
$listItems = $list.Items
$listItemsTotal = $listItems.Count
$newName = "2015-06-WeeklyOperationsReport.pdf"
$originalName = "WeeklyOperationsReport.pdf"

"find document with destination name"

$spSourceItems = $list.Items | where {$_['Name'] -eq $newName}

if($spSourceItems -ne $null)
{
$spSourceItems | ForEach-Object {
"get original week number: "+$_["WeekNumber"]
$originalWeekNumber = $_["WeekNumber"]
"saved original week number: "+$originalWeekNumber
"delete document with destination name"
$_.Delete()
}
}

"rename original document to destination name"

$spSourceItems = $list.Items | where {$_['Name'] -eq $originalName}

if($spSourceItems -ne $null)
{
"originalWeekNumber: "+ $originalWeekNumber
$spSourceItems | ForEach-Object {
$_["Name"] = $newName
$_["Week"] = $originalWeekNumber
$_.Update()
}
}

$web.Dispose();


The value of variable $originalWeekNumber is:



float;#6.00000000000000



I got this error:



Exception calling "Update" with "0" argument(s): "Invalid number value.


A number field contains invalid data. Please check the value and try again." At C:\Users\jack\Desktop\Untitled2.ps1:36 char:18 + $_.Update <<<< () + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException



This is row 36:



$_["Week"] = $originalWeekNumber


what is the issue? How to set a float value on a number column?








0 commentaires:

Enregistrer un commentaire