Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Error: Cannot convert value "Note" to type "System.Type". Error: "Invalid cast from 'Microsoft.SharePoint.SPFieldType' to 'System.Type'."

$
0
0

Hi,

I am trying to access a multiline text field using powershell. I am tring to use "GetFieldValueAsText" option.

I have tried the below code:

 foreach($item in $listItems)
    {
        Write-Host $item.Title


        $calculatedfield = $item.Fields["Test Notes"] -as [Microsoft.SharePoint.SPFieldType]::Note;

        $item["Test Notes"] = $calculatedfield.GetFieldValueAsText($item["Test Notes"]);


        $item.SystemUpdate();

    }


I am getting the below error:

Cannot convert value "Note" to type "System.Type". Error: "Invalid cast from 'Microsoft.SharePoint.SPFieldType' to 'System.Type'."
At \RemoveCharacters.ps1:26 char:9+         $calculatedfield = $item.Fields["Test Notes"] -as [Microsoft. ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : InvalidArgument: (:) [], RuntimeException+ FullyQualifiedErrorId : InvalidCastIConvertible

You cannot call a method on a null-valued expression.
At \RemoveCharacters.ps1:28 char:9
+         $item["Test Notes"] = $calculatedfield.GetFieldValueAsText($i ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException+ FullyQualifiedErrorId : InvokeMethodOnNull

How to fix this? How to use the option GetFieldValueAsText in powershell for multiline column?

Thanks


Viewing all articles
Browse latest Browse all 11571

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>