Try our conversational search powered by Generative AI!

Using FindPagesWithCriteria

Vote:
 

Hi everyone, i wonder if someone else has come accross this issue. I am trying to use FindPagesWithCriteria and i am creating my property criteria as like this:

                PropertyCriteria dateCriteria = new PropertyCriteria();
                dateCriteria.Condition = CompareCondition.GreaterThan;
                dateCriteria.Name = "PageStopPublish";                
                dateCriteria.Type = PropertyDataType.Date;
                dateCriteria.Value = DateTime.Now.ToString();
                dateCriteria.Required = true;
                dateCriteria.IsNull = true;

    so i am trying to find all the pages that are not expired. However, some pages may not have StopPublish property set in which case Datetime.MaxValue should be used. But in this particular case (no StopPublish value set) FindPagesWithCriteria will not return any results. Is there a reason for this or is it a bug? As a workaround, i am returning using PageTypeName criteria and then applying some additional filterin for returned PageDataCollection

#75846
Oct 08, 2013 16:59
Vote:
 

I'm assuming that you are adding dateCriteria to a PropertyCriteriaCollection before doing FindPagesWithCriteria (it's not included in your code) - doing FPWC with an empty PropertyCriteriaCollection as parameter will obviously return no results :-)

Your criteria likely returns no results because you're using the IsNull property wrong. When using IsNull, the Value property is irrelevant (since you're just checking whether the property is null), and you must use CompareCondition.Equal. Your criteria should look like this:

PropertyCriteria dateCriteria = new PropertyCriteria();
dateCriteria.Condition = CompareCondition.Equal; // important
dateCriteria.Name = "PageStopPublish";               
dateCriteria.Type = PropertyDataType.Date;
//dateCriteria.Value = DateTime.Now.ToString(); // irrelevant
dateCriteria.Required = true;
dateCriteria.IsNull = true;

The above criteria will find all pages where PageStopPublish is not set. However, this will not give you pages where PageStopPublish IS set, but not yet expired.
These two criterias are in conflict with each other and you won't be able to fulfill them both in a single FPWC call.

I would do a workaround like you describe - first retrieve all relevant pages using another criteria, then filter that PageDataCollection for variations of the PageStopPublish property value using LINQ.

 

 

#75904
Oct 10, 2013 15:14
Vote:
 

I'm tring to use as a way to discover all the subscribable pages beneath the StartPage.  Your post @Arild made me think I might crack it with

pc.Condition = EPiServer.Filters.CompareCondition.NotEqual;
pc.Name = "EPSUBSCRIBE";
pc.IsNull = true;

Regardless if whether my CompareCondition is Equal or NotEqual my PageDataCollection results in (seemingly) all pages beneath the StartPage :-(

If IsNull is false the FPWC throws an exception as EPSUBSCRIBE is clearly not set for all pages.  

I'm confused by the correct usage of PropertyCriteria - especially where the property is a Selected/Not Selected value

----

BTW: I had expected to be able to get the subscription page listin an easier way using the SubscriptionService but to now avail.  The list is required to be added to an Admin->Tasks plugin ... not as a control on a normal Page type.  Clues on a lightweight way achieve getting this list as a PageDataCollection would be appreciated.

#77412
Nov 19, 2013 0:58
Vote:
 

That won't work. Invert your query to look for pages where EPSUBSCRIBE is True:

pc.Type = PropertyDataType.Boolean;
pc.Value = "True";
pc.Required = true;
pc.Name = "EPSUBSCRIBE";

    

 

#77429
Nov 19, 2013 9:06
Vote:
 

Thank you Arild.  You've dispelled my confusion - this works now as expected. 

#77459
Nov 19, 2013 23:53
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.