Question

I am working in Ektron 9.0.

I have two different custom property associated with a taxonomy in Ektron.

Say, Taxonomy called "P",this has got two custom properties,

*P1 *P2

Each of these custom property has its own value.

(For eg: *P1 - V1 *P2 -V2)

Now i am trying to pull all taxonomies in Ektron,based on the names and values of these custom properties.

i.e, get all taxonomies in Ektron which has got custom property name as P1 and corresponding value as V1 AND another custom property name as P2 and corresponding value as V2.

Code :

CriteriaFilterGroup<TaxonomyCustomProperty> criteriaFilterGrp1= new CriteriaFilterGroup<TaxonomyCustomProperty>();
criteriaFilterGrp1.AddFilter(TaxonomyCustomProperty.Name,
CriteriaFilterOperator.EqualTo,"P1");
criteriaFilterGrp1.AddFilter(TaxonomyCustomProperty.Value,
                  CriteriaFilterOperator.EqualTo, "V1");
criteriaFilterGrp1.Condition = LogicalOperation.And;
custCtriteria.FilterGroups.Add(criteriaFilterGrp1);

CriteriaFilterGroup<TaxonomyCustomProperty> criteriaFilterGrp2= new CriteriaFilterGroup<TaxonomyCustomProperty>();
criteriaFilterGrp2.AddFilter(TaxonomyCustomProperty.Name,
              CriteriaFilterOperator.EqualTo, "P2";
criteriaFilterGrp2.AddFilter(TaxonomyCustomProperty.Value,
              CriteriaFilterOperator.EqualTo, "V2");
custCtriteria.FilterGroups.Add(criteriaFilterGrp2);

Here,When I Add the Filter criteria by the two taxonomy names and their corresponding value as as follows, I am not getting any results,as it is looking for a taxonomy custom property that satisfies the all four conditions that I have given.

How can i resolve this?

Was it helpful?

Solution

My guess is that the underlying code is behaving differently from how it might be expected to operate - instead of handling taxonomy items with custom properties, it is handling the properties themselves. This is consistent with the behavior of other ektron APIs in terms of its typing, but inconsistent in that it returns the associated taxonomy items themselves (though this is clearly the more desirable outcome). With respect to this design, it makes sense that you cannot retrieve a custom property that has name equal to p1 and p2.

The solution is to retrieve lists for each property you want to filter by independently, and then intersect these lists. Conveniently, ektron returns iQueryable lists, so you can do this trivially with linq:

CriteriaFilterGroup<TaxonomyCustomProperty> criteriaFilterGrp1= new CriteriaFilterGroup<TaxonomyCustomProperty>();
criteriaFilterGrp1.AddFilter(TaxonomyCustomProperty.Name,
CriteriaFilterOperator.EqualTo,"P1");
criteriaFilterGrp1.AddFilter(TaxonomyCustomProperty.Value,
                  CriteriaFilterOperator.EqualTo, "V1");
criteriaFilterGrp1.Condition = LogicalOperation.And;
custCtriteria.FilterGroups.Add(criteriaFilterGrp1);
var itemsWithProp1= taxManager.getList(custCtriteria);

custCtriteria = new criteria();
CriteriaFilterGroup<TaxonomyCustomProperty> criteriaFilterGrp2= new CriteriaFilterGroup<TaxonomyCustomProperty>();
criteriaFilterGrp2.AddFilter(TaxonomyCustomProperty.Name,
              CriteriaFilterOperator.EqualTo, "P2";
criteriaFilterGrp2.AddFilter(TaxonomyCustomProperty.Value,
              CriteriaFilterOperator.EqualTo, "V2");
custCtriteria.FilterGroups.Add(criteriaFilterGrp2);
var itemsWithProp2 = taxManager.getList(custCtriteria);

var itemsWithBoth = itemsWithProp1.Intersect(itemsWithProp2);

While this is not the most elegant or efficient solution, I'm not sure that there is a better way within Ektron's API, outside of crafting a custom SQL query.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top