Skip to main content
added 78 characters in body
Source Link
Sayantan Basu
  • 2.6k
  • 11
  • 15

I have faced same type issue with multiple CustomMetaValueCriteria. So to overcome that, I have changed my query like below. For me it is working fine now. Could you try the below code once -

This is Just a sample, you can change it according to your requirement -

Query query = new Query();
            ItemSchemaCriteria schemaCriteria = new ItemSchemaCriteria(300); PublicationCriteria publicationCriteria = new PublicationCriteria(8);
            ItemTemplateCriteria templateCriteria = new ItemTemplateCriteria(4787);
            CustomMetaValueCriteria validityStart = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("ValidityStart"), DynConfig.GetCurrentCMSDate(), Criteria.GreaterThanOrEqual);
            CustomMetaValueCriteria validityEnd = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("ValidityEnd"), DynConfig.GetCurrentCMSDate(), Criteria.LessThanOrEqual);

            Criteria[] criteriaList1 = { schemaCriteria, publicationCriteria, templateCriteria, validityStart };
            Criteria[] criteriaList2 = { schemaCriteria, publicationCriteria, templateCriteria, validityEnd };
            AndCriteria firstCriteria = CriteriaFactory.And(criteriaList1);
            AndCriteria secondCriteria = CriteriaFactory.And(criteriaList2);
            OrCriteria mainCriteriaCriteria = new OrCriteria(firstCriteria, secondCriteria);
            NotInCriteria finalCriteria = new NotInCriteria(mainCriteriaCriteria); 
query.Criteria = finalCriteria; 
var componentsUris = query.ExecuteQuery();

Let me know if it works fine for you.

I have faced same type issue with multiple CustomMetaValueCriteria. So to overcome that, I have changed my query like below. For me it is working fine now. Could you try the below code once -

Query query = new Query();
            ItemSchemaCriteria schemaCriteria = new ItemSchemaCriteria(300); PublicationCriteria publicationCriteria = new PublicationCriteria(8);
            ItemTemplateCriteria templateCriteria = new ItemTemplateCriteria(4787);
            CustomMetaValueCriteria validityStart = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("ValidityStart"), DynConfig.GetCurrentCMSDate(), Criteria.GreaterThanOrEqual);
            CustomMetaValueCriteria validityEnd = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("ValidityEnd"), DynConfig.GetCurrentCMSDate(), Criteria.LessThanOrEqual);

            Criteria[] criteriaList1 = { schemaCriteria, publicationCriteria, templateCriteria, validityStart };
            Criteria[] criteriaList2 = { schemaCriteria, publicationCriteria, templateCriteria, validityEnd };
            AndCriteria firstCriteria = CriteriaFactory.And(criteriaList1);
            AndCriteria secondCriteria = CriteriaFactory.And(criteriaList2);
            OrCriteria mainCriteriaCriteria = new OrCriteria(firstCriteria, secondCriteria);
            NotInCriteria finalCriteria = new NotInCriteria(mainCriteriaCriteria); 
query.Criteria = finalCriteria; 
var componentsUris = query.ExecuteQuery();

Let me know if it works fine for you.

I have faced same type issue with multiple CustomMetaValueCriteria. So to overcome that, I have changed my query like below. For me it is working fine now. Could you try the below code once -

This is Just a sample, you can change it according to your requirement -

Query query = new Query();
            ItemSchemaCriteria schemaCriteria = new ItemSchemaCriteria(300); PublicationCriteria publicationCriteria = new PublicationCriteria(8);
            ItemTemplateCriteria templateCriteria = new ItemTemplateCriteria(4787);
            CustomMetaValueCriteria validityStart = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("ValidityStart"), DynConfig.GetCurrentCMSDate(), Criteria.GreaterThanOrEqual);
            CustomMetaValueCriteria validityEnd = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("ValidityEnd"), DynConfig.GetCurrentCMSDate(), Criteria.LessThanOrEqual);

            Criteria[] criteriaList1 = { schemaCriteria, publicationCriteria, templateCriteria, validityStart };
            Criteria[] criteriaList2 = { schemaCriteria, publicationCriteria, templateCriteria, validityEnd };
            AndCriteria firstCriteria = CriteriaFactory.And(criteriaList1);
            AndCriteria secondCriteria = CriteriaFactory.And(criteriaList2);
            OrCriteria mainCriteriaCriteria = new OrCriteria(firstCriteria, secondCriteria);
            NotInCriteria finalCriteria = new NotInCriteria(mainCriteriaCriteria); 
query.Criteria = finalCriteria; 
var componentsUris = query.ExecuteQuery();

Let me know if it works fine for you.

Post Undeleted by Sayantan Basu
Post Deleted by Sayantan Basu
Source Link
Sayantan Basu
  • 2.6k
  • 11
  • 15

I have faced same type issue with multiple CustomMetaValueCriteria. So to overcome that, I have changed my query like below. For me it is working fine now. Could you try the below code once -

Query query = new Query();
            ItemSchemaCriteria schemaCriteria = new ItemSchemaCriteria(300); PublicationCriteria publicationCriteria = new PublicationCriteria(8);
            ItemTemplateCriteria templateCriteria = new ItemTemplateCriteria(4787);
            CustomMetaValueCriteria validityStart = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("ValidityStart"), DynConfig.GetCurrentCMSDate(), Criteria.GreaterThanOrEqual);
            CustomMetaValueCriteria validityEnd = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("ValidityEnd"), DynConfig.GetCurrentCMSDate(), Criteria.LessThanOrEqual);

            Criteria[] criteriaList1 = { schemaCriteria, publicationCriteria, templateCriteria, validityStart };
            Criteria[] criteriaList2 = { schemaCriteria, publicationCriteria, templateCriteria, validityEnd };
            AndCriteria firstCriteria = CriteriaFactory.And(criteriaList1);
            AndCriteria secondCriteria = CriteriaFactory.And(criteriaList2);
            OrCriteria mainCriteriaCriteria = new OrCriteria(firstCriteria, secondCriteria);
            NotInCriteria finalCriteria = new NotInCriteria(mainCriteriaCriteria); 
query.Criteria = finalCriteria; 
var componentsUris = query.ExecuteQuery();

Let me know if it works fine for you.