1

Can any please explain me how to add multiple items to the multilist field. For me only last item is getting selected.

$item.Editing.BeginEdit()
$allItems = Get-ChildItem -Path '/sitecore/content/ListManagerTask' -Recurse
foreach($multilistItem in $allItems) { $item[$templateField.Name] += $multilistItem.ID; } 
$item.Editing.EndEdit() | Out-Null`

I want to assign all items in $allItems to multilist.

This is how i'm getting

3

You haven't added any | character to split the IDs of selected items. This works:

$item.Editing.BeginEdit() 

$allItems = Get-ChildItem -Path '/sitecore/content/ListManagerTask' -Recurse

foreach($multilistItem in $allItems) { 
    if (![string]::IsNullOrEmpty($item[$templateField.Name])) {
        $item[$templateField.Name] += "|";
    }
    $item[$templateField.Name] += $multilistItem.ID.ToString()
} 

$item.Editing.EndEdit() | Out-Null
  • 1
    There are some code snippets which include working with multilist here doc.sitecorepowershell.com/code-snippets – Michael West Jul 12 at 13:28
  • Thank you so much sir...Its working fine... – kohila vani Jul 12 at 13:42
  • @kohilavani I'm glad it worked. If you find this answer useful, you should mark it as correct. Upvoting is also encouraged. – Marek Musielak Jul 12 at 13:47
  • 1
    Wow -- I was just looking for the same thing today... I found it more efficient to build the string and then do the assignment once rather than continuously editing the item – Mike Jul 12 at 15:06
  • Item is edited only once. It's the field value which is updated multiple times. But you're right. It could be more efficient to build the string first and then assign it to the field value. – Marek Musielak Jul 12 at 15:59

Your Answer

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

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