1

I want to compare two MultiList in terms of, comparing Selected Items. I have a MultiList where users can select what items they want to be selected.

Here is the image of it:

enter image description here

Now I have a Tagging section, like almost every item, in Media Item, and there items can also be selected. Now I am asking, is it possible to compare Selected Items from the "user MultiList", like when user can select what they want, to the MultiList in Media Item

Tagging Section: enter image description here

Here is the code so far:

@($rootItem) + @($rootItem.Axes.GetDescendants() | Initialize-Item) | 
    ForEach-Object {
        $currentItem = $_
        Get-ItemField -IncludeStandardFields -Item $currentItem -ReturnType Field -Name "*" `
            | ForEach-Object{
                ForEach($i in $value) {
                if($PSItem.Value -match $i.DisplayName -and $PSItem.Name.Contains("__Semantics")){
                    [pscustomobject]@{
                        "Name"=$currentItem.DisplayName
                        "ItemId"=$currentItem.ID
                        "FieldName"=$_.Name
                        "ItemPath" = Get-MediaUrl($currentItem)
                    }
Copy-Item -Path $currentItem.ItemPath -Destination $folderToMove.Paths.FullPath;
                }
                }
                
            } 
} | Sort-Object -Unique ItemID | Show-ListView

$rootItem is just the path to the folder, for example sitecore/Media Library/Images $value is the value from the MultiList display names

2
  • So you want to find all the media library items under selected root which have same set of tags like you selected when running a report? Or at least of from those selected when running a report? Or all of those selected when running a report and potentially some more?
    – Marek Musielak
    Dec 16, 2021 at 16:20
  • @MarekMusielak I only want to find those media library items that have at least one or all of the selected items. If that is really hard to make, then same set of tags.
    – Samke11
    Dec 16, 2021 at 16:24

1 Answer 1

1

I managed to do it on my own. Here is the answer, that works for me this time

@($rootItem) + @($rootItem.Axes.GetDescendants() | Initialize-Item) | 
    ForEach-Object {
        $currentItem = $_
        $multilistField = [Sitecore.Data.Fields.MultilistField]$currentItem.Fields["__Semantics"]

        $multilistItems = $multilistField.GetItems()

        foreach($multilistItem in $multilistItems){
           if($value.DisplayName -match $multilistItem.DisplayName){
               Write-Host $currentItem.DisplayName
                    [pscustomobject]@{
                        "Name"=$currentItem.DisplayName
                        "ItemId"=$currentItem.ID
                        "FieldName"=$_.Name
                        "ItemPath" = Get-MediaUrl($currentItem)
                    }
Copy-Item -Path $currentItem.ItemPath -Destination $folderToMove.Paths.FullPath;
                }
        }
    } | Sort-Object -Unique ItemID | Show-ListView    

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.