+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Filter dynamic content types by related data items.

Filter dynamic content types by related data items.

6 posts, 0 answered
  1. Uttam
    Uttam avatar
    21 posts
    Registered:
    17 Mar 2015
    02 Jun 2015
    Link to this post

    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!!!

  2. Uttam
    Uttam avatar
    21 posts
    Registered:
    17 Mar 2015
    04 Jun 2015
    Link to this post

    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.

  3. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    30 Sep 2016
    09 Jul 2015
    Link to this post
    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
     
  4. Nitin
    Nitin avatar
    1 posts
    Registered:
    23 Nov 2015
    01 Dec 2015
    Link to this post

    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.

  5. Kiko
    Kiko avatar
    5 posts
    Registered:
    07 May 2012
    18 Apr in reply to Sabrie Nedzhip
    Link to this post

    Hi,

     

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

    ¿Is that possible?

    Thanks in advance.

  6. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    30 Sep 2016
    21 Apr
    Link to this post
    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
     
6 posts, 0 answered