Filter dynamic content types by related data items.

Posted by Community Admin on 04-Aug-2018 04:39

Filter dynamic content types by related data items.

All Replies

Posted by Community Admin on 02-Jun-2015 00:00

Hi All,

Quick question on Sitefinity API, how to filter dynamic Content types by related data items ?

Here is my code which didn't work for me.

 var contentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.​ContentModel.ContentModel");
var contentDataList = dynamicModuleManager.GetDataItems(contentType );
var FilteredItems = contentDataList.ToArray().Where(p =>
p.GetRelatedItems("Attraction").OfType<DynamicContent>().Any(s
=> s.GetValue<string>("Title").Equals("Museum")));

where "Attraction" is the related data items to ​ContentModel dynamic content type and I want to filter all content items by specific attraction related content title.

Thanks!!!

Posted by Community Admin on 04-Jun-2015 00:00

After more research, I found that "GetRelatedItems" is coming as null if the dynamic content types exceeds 200+ and works fine for 5-10 pieces of content. Is it a bug or because of performance Sitefiniy don't return Related data if the request has 200+ content items ?

Thanks.

Posted by Community Admin on 09-Jul-2015 00:00

Hi Uttam,

Can you please refer to the following article and try the sample we have provided there for querying dynamic content items by related data.

Regards,
Sabrie Nedzhip
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 01-Dec-2015 00:00

I am facing with a similar Problem and have not got the solution yet.

Please refer to the below mentoined line of code:

IQueryable<Telerik.Sitefinity.Lists.Model.ListItem> listItems = listManager.GetListItems().Where(li => li.Parent.Id == ListID && li.Status == ContentLifecycleStatus.Live && li.Visible == true && li.GetRelatedItems<DynamicContent>("ExpertType").FirstOrDefault().GetValue<string>("Title") == "Financial Team").OrderBy(x => x.Ordinal);

I am trying to filter list items with a dynamic module used as custom field on the list item but getting below mentioned error:

SubQueries involving non-persistent sources not supported : Telerik.Sitefinity.DynamicModules.Model.DynamicContent[].All(z => (z.FieldValue("Title") == "Financial Team"))

Please help.

Posted by Community Admin on 18-Apr-2016 00:00

Hi,

 

I need to filter by two related data values...

¿Is that possible?

Thanks in advance.

Posted by Community Admin on 21-Apr-2016 00:00

Hi,

Please use the below approach for filtering the items by related data: http://docs.sitefinity.com/example-query-dynamic-content-by-related-data

Here is also another sample code for more details on filtering dynamic modules by related pages:

Type schoolType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Schools.School");
   
            var contentLinksManager = ContentLinksManager.GetManager();
   
            // the type of your module which has Pages as related data
            string parentType = "Telerik.Sitefinity.DynamicTypes.Model.Schools.School";
   
            // the ID of the Page you would like to filter by.
            Guid PageNodeId = new Guid("216665AC-33A7-6917-80C9-FF0000B37697");
   
            // here you get the IDs of dynamic module items
      // which has as related data a Page with the specified ID
            var parentItemContentLinks = contentLinksManager.GetContentLinks()
                .Where(c => c.ParentItemType == parentType && c.ChildItemId == PageNodeId)
                .Select(c => c.ParentItemId).ToList();       
   
            // here you get the filtered dynamic module items by their IDs
            var result = dynamicModuleManager.GetDataItems(schoolType)
                .Where(d => parentItemContentLinks.Contains(d.OriginalContentId) && d.Status == ContentLifecycleStatus.Live);

Please note to replace the dynamic module type with your module type and to replace the pageNodeId with an Id of your page you want to filter the dynamic items by.

I have also recorded a short video demonstrating the result after executing the code: http://screencast.com/t/wdiXNIeT

You can use the above approach to filter by two related data fields.

Regards,
Sabrie Nedzhip
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed