Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > RandomDocument Filtered Selection View modes: 
User avatar
Member
Member
dmonson-mspmag - 10/31/2011 11:48:19 AM
   
RandomDocument Filtered Selection
I tried the Developer Guide for documentation on the RandomDocument, but I couldn't find what I'm looking for.

I am hoping to apply a filter to the Documents targeted by the RandomDocument query based on a boolean Field in the Document. Documents of both "True" and "False" boolean values are contained within the same path/directory in the CMS.

Let's say for example, I want to display 3 random Agents, but only from those documents with a boolean value of "True" in the Field "AgentExpanded".

I need to filter by the boolean before the selection. I can't just select three documents, and then only display them IF they are "True" - as I might end up with 0 documents returned (if all three documents return a boolean of "False").

Any leads on how I might accomplish this? If I absolutely must resort to pulling the "True" documents into a unique directory in the CMS, that would be possible - though not ideal.

Thanks!!

User avatar
Kentico Support
Kentico Support
janh-kentico - 11/1/2011 3:40:32 AM
   
RE:RandomDocument Filtered Selection
Hello,

Of course, I will show you, how to display 3 random documents from one location by using repeater webpart, so please place this webpart to your page and fill following properties:

Path: (path to your document location e.g. /test/%)
Document types: (your document type e.g. CMS.MenuItem)
ORDER BY expression: NEWID()
Select top N documents: 3
WHERE condition: AgentExpanded = true

This should fit your needs.

Best regards,
Jan Hermann


User avatar
Member
Member
dmonson-mspmag - 11/1/2011 10:06:58 AM
   
RE:RandomDocument Filtered Selection
Can you show me how to insert the WHERE condition into my .aspx code with proper syntax?

<cms:RandomDocument ID="uxRandomProduct" ClassNames="SREA.Agent" Path="/Agents/%" TransformationName="SREA.Agent.AgentFeatureHome" SelectRandomN="3" runat="server" />

User avatar
Member
Member
dmonson-mspmag - 11/1/2011 12:07:40 PM
   
RE:RandomDocument Filtered Selection
We're using ASPX templates - sorry, I should have specified that.

I'm guessing I can go into the Site Manager > Document types > Agent > Queries

and create a New Query with the WHERE condition, but I still don't know how to implement a doc type's query into the RandomDocument funtion.

Sorry - I'm just learning Kentico. Thanks for your help.

User avatar
Kentico Support
Kentico Support
janh-kentico - 11/2/2011 4:17:02 AM
   
RE:RandomDocument Filtered Selection
Hello,

In your case it would be better to use classic repeater instead of the RandomDocument webpart. So the code will be:

<%@ Register Src="~/CMSWebParts/Viewers/Documents/cmsrepeater.ascx" TagName="repeater" TagPrefix="uc1" %>

<uc1:repeater runat="server" ID="uxRandomProduct" ClassNames="SREA.Agent" Path="/Agents/%" OrderBy="NEWID()" SelectTopN="3" WhereCondition="AgentExpanded=true" TransformationName="SREA.Agent.AgentFeatureHome" />

Best regards,
Jan Hermann