0

I am looking to extract the multilist , dropdown list field value of an item using PowerShell query.

    $item = Get-Item -Path master -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"

$rawIds = [Sitecore.Data.Fields.MultilistField]$item.Fields["My checklist field name"]

$selectedItems = $rawIds.GetItems()

foreach($selectedItem in $selectedItems){
    $selectedItem.DisplayName
}

Error I am getting is You cannot call a method on a null valued expression

2
  • What have you tried? There is nothing special about getting a field value from either of these
    – Mark Cassidy
    Commented Nov 30, 2021 at 8:45
  • $item = Get-Item -Path master -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}" $rawIds = [Sitecore.Data.Fields.MultilistField]$item.Fields["My checklist field name"] $selectedItems = $rawIds.GetItems() foreach($selectedItem in $selectedItems){ $selectedItem.DisplayName } Error I am getting is You cannot call a method on a null valued expression
    – Harish
    Commented Nov 30, 2021 at 8:47

1 Answer 1

2

Cast $item.Fields["FieldName"} to Sitecore.Data.Fields.MultilistField:

$multilistField = [Sitecore.Data.Fields.MultilistField]$item.Fields["FieldName"]

$multilistItems = $multilistField.GetItems()

foreach($multilistItem in $multilistItems){
    # do whatever you want with item from multilist
}

EDIT AFTER OP CHANGED THEIR QUESTION

The error you get means that one of your variables is null.

Check which one is that. It can be either

  • $item itself
  • or $item.Fields["My checklist field name"]
1
  • Hi @Marek , Thanks for your input, It really helped me solve the problem.
    – Harish
    Commented Nov 30, 2021 at 13:00

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.