7

I have below two Criteria -

  1. Criteria searchCriteria = CriteriaFactory.And(ItemSchemaCriteria, PublicationCriteria);

  2. finalCriteria = CriteriaFactory.And(andCriteria);

here andCriteria is an array of some Keyword Criteria.

Now when I try to add these both criteria and assign it in another Criteria named myCriteria the as below:

myCriteria = searchCriteria.addCriteria(finalCriteria);

Below compilation error comes:

"Type mismatch: cannot convert from void to Criteria"

NOTE: As I debug and found that both searchCriteria and finalCriteria are not NULL.

Could somebody give me some pointers here to fix this error?

2
  • 2
    I suspect that addCriteria is a void method and it modifies your search criteria in place, hence you see that error when you try to assign the result of addCritera to your myCriteria variable. Can you post a more complete example of your code? Commented Dec 27, 2013 at 11:25
  • Not sure if this is the right place for this question given that this is pretty much a pure programming problem and not necessarily related to Tridion (aside from the fact that Tridion libraries are being used).
    – Ant P
    Commented Dec 27, 2013 at 12:12

1 Answer 1

9

As hinted at by Nick, the Criteria.AddCriteria method doesn't return a Criteria object, so you can't assign it as you're trying to. What you probably want is something like this:

searchCriteria.AddCriteria(finalCriteria);
myCriteria = searchCriteria;

Note that if you do this, searchCriteria and myCriteria will be the same object instance, so changes to one will affect the other (until one of them is reassigned).

1
  • yes, Ant you are correct. Thanks to NVanderEnde also.
    – user584
    Commented Dec 27, 2013 at 12:16

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.