1

I have a little bit of confusion regarding the Multilist Field in Sitecore. Basically, I want to get all of the selected MultiList Field in PowerShell to do stuff with them.

Is it possible to make those values in array?

Here is the code so far:

$props = @{
    Title = "Get All Media Items by Tag"
    Description = "Get all Media items by Tag"
    OkButtonName = "Run Report"
    CancelButtonName = "Cancel"
    Parameters = @(
        @{ Name = "TagName"; Title = "Tag Name"; Editor = "multilist"; Source = "/sitecore/system/Settings/Buckets/TagRepository/2021/12/16/14/36" }
        @{ Title = "Note"; Value = "Select Tags you need for the Images from the Tag Repository"; Editor = "info" }
    )
}

$result = Read-Variable @props
if($result -ne "ok") {
    Close-Window
    Exit
}

The path for the Tag Repositoy is bucket, as you know. How to get also path for that? Source = "/sitecore/system/Settings/Buckets/TagRepository/2021/12/16/14/36" }

And this is the picture showing what this code does:

enter image description here

Is there any way to get those selected values and make them in array, or they are in array by default?

I personally think maybe $TagName.Values would do the trick, or something like that

1 Answer 1

1

You are correct with your approach. You just have a typo. Use Name = "TagNames" instead of Name = "TagName" in your props. Then you can use $TagNames:

$props = @{
    Title = "Get All Media Items by Tag"
    Description = "Get all Media items by Tag"
    OkButtonName = "Run Report"
    CancelButtonName = "Cancel"
    Parameters = @(
        @{ Name = "TagNames"; Title = "Tag Name"; Editor = "multilist"; Source = "/sitecore/system/Settings/Buckets/TagRepository/2021/12/16/14/36" }
        @{ Title = "Note"; Value = "Select Tags you need for the Images from the Tag Repository"; Editor = "info" }
    )
}

$result = Read-Variable @props

if($result -ne "ok") {
    Close-Window
    Exit
}

foreach ($tag in $TagNames) {
    # ... do whatever you need with your tag
}
2
  • Thank you this helped me. Do you have any tips how to get Tagging field in other items. Like beacuse it is MultiList field as well, but how to compare these two? Like from the Tag MultiList to the Item MultiList if they have same selected item name
    – Samke11
    Commented Dec 16, 2021 at 15:48
  • @Samke11 you should keep 1 question inside 1 post. Best create a new question with screenshots from your system and marking what exactly you want to achieve and what you already have.
    – Marek Musielak
    Commented Dec 16, 2021 at 16: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.