0

I am using PnP.Powershell version 2.12.0.

I am trying to set values of two new managed metadata columns in a list using values from other columns. But I keep getting the following error:

Cannot bind parameter 'ListItem'. Cannot convert the "System.Collections.Generic.Dictionary2[System.String,System.Object]" value of type | "System.Collections.Generic.Dictionary2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object,
| System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]" to type "Microsoft.SharePoint.Client.ListItem".

First I get the list item and the relevant fields as follows:

$colItems = (Get-PnPListItem -List $oList -id 236 -Fields “Orig Field 1”, “Orig Field 2”, “New Field 1”, “New Field 2”).FieldValues

This is technically a collection, so I used a forEach loop to get $oItem. All the columns are managed metadata fields.

Then I tried two approaches to setting "New Field 1"

Set-PnPTaxonomyFieldValue -ListItem $oItem -InternalFieldName 'New Field 1' -TermID "ID String"

Where "ID String" is actually the GUID for the term, and

Set-PnPTaxonomyFieldValue -ListItem $oItem -InternalFieldName 'DEDiscipline' -TermPath = $NewValue

Where $NewValue is in the form "Term Group|Term Set|Term"

Nothing works, and I keep getting the error above. I have gone into Entra ID admin and added additional permissions in Microsoft Graph and SharePoint, so I have Sites.FullControl.All in both.

I have also tried using just Set-PnPListItem as follows:

Set-PnPListItem -List $oList -Identity $oItem -Values @{"New Field 1"=$NewValue}

I've pasted my API permissions below:

API Permissions

I use the following syntax for connecting:

Connect-PnPOnline -Url $SiteURL -ClientId <clientID> -Tenant <Domain>.onmicrosoft.com -Interactive
New contributor
Dan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
9
  • Would you like to copy data from column1 to column2 in the same list for the items? Commented Dec 9 at 12:01
  • I am trying to use the value of old column 1 to set the value of new column 1 and old column 2 to set new value 2. It's not exactly a copy, because they're different but similar term sets. I'm migrating from the sandbox solution to a permanent solution.
    – Dan
    Commented Dec 9 at 15:29
  • Can you show a screenshot of all your api permissions of your app?
    – Danny
    Commented 2 days ago
  • @Danny, I added the screenshot.
    – Dan
    Commented 2 days ago
  • How do you use Connect-PnPonline?
    – Danny
    Commented 2 days ago

1 Answer 1

1

I can reproduce your error.

When u use:

$colItems = (Get-PnPListItem -List $oList -id 236 -Fields “Orig Field 1”, “Orig Field 2”, “New Field 1”, “New Field 2”).FieldValues

You don't get a ListItem object but a collection of field values. You should remove .FieldValues so you get a ListItem oject.

So try:

$listItem = (Get-PnPListItem -List $oList -id 236 -Fields “Orig Field 1”, “Orig Field 2”, “New Field 1”, “New Field 2”)
Set-PnPTaxonomyFieldValue -ListItem $listItem -InternalFieldName 'New Field 1' -TermID "ID String"

comment by TS

Thanks! I tried that and it worked. I still need to access the list of fields, to pull some values, but now I do it using the following:

$NewValue = $PathPrefix + $ListItem.FieldValues.OrigField1.Label

@Danny, I appreciate the help!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.