0

I am trying to build a predicate, but if I don't hard code a value it does not work. I need to pass in a list of values. If I hard code a value the filter works. Any ideas on what I can do to get this to work? Is this a limit of PowerShell?

Function Get-ProductList($taglist){
   $criteriaTemplate = @(
    @{Filter = "Equals"; Field = "_templatename"; Value = "ProductMarketTags"},
    #@{Filter = "ContainsAny"; Field = "market_sm"; Value = [string[]]@("77192676e47249f0b2531639538296f1")}
    @{Filter = "ContainsAny"; Field = "market_sm"; Value = [string[]]@($taglist)}
    )
    
    $predicateTemplate = New-SearchPredicate -Criteria $criteriaTemplate

    $props = @{
        Index = "index_marketingproducts"
        WherePredicate = $predicateTemplate
    }

    Find-Item @props
}

$allItems = Get-ChildItem -Path 'master:///sitecore/content/Products' -Recurse

$allItems | ForEach-Object {

    # If the current item has a certain template, print out its path in the tree
    if ($_.TemplateName -eq 'Page' -And $_.ID -eq '{0883B297-E244-52A0-8DBC-527D6F004428}') {
        
        if($_["Market"])
        {
            Foreach ($markettag in $_["Market"].Split("|"))
            {
                $taglist = "'" + $markettag.replace('}','').replace('{','').replace('-','') + "'";                
            }
            Get-ProductList $taglist
        }

    }
}
4
  • 1
    As far as I recall you don't have to remove the brackets and dashes. SPE should do that for you. You can also use the proper ID type. Jun 25 at 16:45
  • @MichaelWest looks like it works for one ID, but does not seem to work for multiple. I tried just the | separated and comma, but no results.
    – RReilley
    Jun 25 at 18:44
  • I can work with one at a time though if I have to. :)
    – RReilley
    Jun 25 at 18:54
  • Looks like you are using the Criteria format which only handles AND logic. We have a Predicate format which would allow you to use OR logic. doc.sitecorepowershell.com/appendix/indexing/… Jun 25 at 19:26

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.