I am trying to update a metadata field when adding an item to document library. All the other columns are updating. The error is on this line and basically $taxfield is returning null.

$taxField = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$spItem.Fields["Region"]
$termSet = $termStore.GetTermSet($taxField.TermSetId) >> error on this line.

I am running this code with Admin and have full permission to the list.

= = = Error = = =

You cannot call a method on a null-valued expression. At C:\ps\AddFile.ps1:60 char:30 + $taxFieldState.SetFieldValue <<<< ($spItem, $termsST) + CategoryInfo : InvalidOperation: (SetFieldValue:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

  • try using the $list.Fields["Region"] instead of $spItem – David Lozzi Jun 22 '12 at 20:47
  • Did not help. $list=$web.Lists["Monthly Sales Report"] – Angie Heimerlake Jun 23 '12 at 0:28
  • What do you get when you use $taxField = $spItem.Fields["Region"]. Also try and paste some more of your code so we can understand what you are doing – Anders Rask Jun 27 '12 at 11:23
  • Do you use a localized version of SharePoint? The DisplayName of the field may be language-dependant! Can you get the field by its InternalName property (like $spItem.Fields.GetFieldByInternalName("InternalNameOfYourField")? – pholpar Apr 30 '15 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.