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

Forums / Module Builder / Get Published Items Only

Get Published Items Only

4 posts, 0 answered
  1. SteveV
    SteveV avatar
    178 posts
    Registered:
    06 Nov 2011
    10 Sep 2014
    Link to this post

    I have a dynamic module that includes a SortOrder field to help control the display order of items.  I'm trying to retreive a list of published items sorted by the "SortOrder" value. I'm using the following code but it returns both published and unpublished items.

    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
    Type auctionPreviewItemType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem");
    var myCollection = dynamicModuleManager.GetDataItems(auctionPreviewItemType).Where(i => i.Status == ContentLifecycleStatus.Live).OrderBy(i => i.GetValue<decimal>("SortOrder"));

    I've also tried:

    var myCollection = dynamicModuleManager.GetDataItems(auctionPreviewItemType).Where(i => i.Status == ContentLifecycleStatus.Live && i.Lifecycle.IsPublished).OrderBy(i => i.GetValue<decimal>("SortOrder"));

    This compiles fine but causes the following exception:

    An exception occured during the execution of 'Extent<Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem>().Where(re-p => (re-p.ApplicationName == OpenAccessProvider.ApplicationName)).Where(re-i => ((Convert(Convert(Convert(Convert(Convert(re-i.Status))))) == 2) AndAlso re-i.Lifecycle.IsPublished)).OrderBy(re-i => re-i.FieldValue("SortOrder"))'. Failure: Identifier 'Lifecycle' is not a parameter or variable or field of 'Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem'. If 'Lifecycle' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias.
    See InnerException for more details.
    Complete Expression:
    .Call System.Linq.Queryable.OrderBy(
        .Call System.Linq.Queryable.Where(
            .Call System.Linq.Queryable.Where(
                .Constant<Telerik.OpenAccess.Query.ExtentQueryImpl`1[Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem]>(Extent<Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem>()),
                '(.Lambda #Lambda1<System.Func`2[Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem,System.Boolean]>))
            ,
            '(.Lambda #Lambda2<System.Func`2[Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem,System.Boolean]>))
        ,
        '(.Lambda #Lambda3<System.Func`2[Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem,System.Decimal]>))
     
    .Lambda #Lambda1<System.Func`2[Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem,System.Boolean]>(Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem $re-p)
    {
        $re-p.ApplicationName == .Constant<Telerik.Sitefinity.DynamicModules.Data.OpenAccessDynamicModuleProvider>(OpenAccessProvider).ApplicationName
    }
     
    .Lambda #Lambda2<System.Func`2[Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem,System.Boolean]>(Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem $re-i)
    {
        (System.Int32)((System.Int32)((System.Int32)((System.Int32)((System.Int32)$re-i.Status)))) == 2 && ($re-i.Lifecycle).IsPublished
    }
     
    .Lambda #Lambda3<System.Func`2[Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem,System.Decimal]>(Telerik.Sitefinity.DynamicTypes.Model.AuctionPreviewItems.AuctionPreviewItem $re-i)
    {
        .Call Telerik.OpenAccess.ExtensionMethods.FieldValue(
            $re-i,
            "SortOrder")
    }

    Any thoughts?

    Thanks--Steve

     

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    15 Sep 2014
    Link to this post
    Hello Steve,

    You should also filter by the Visible property. It should be equal to true and you will get the published items. For instance:
    var myCollection = dynamicModuleManager.GetDataItems(yourType)
        .Where(d=> d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && d.Visible == true);


    Regards,
    Nikola Zagorchev
    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
     
  3. SteveV
    SteveV avatar
    178 posts
    Registered:
    06 Nov 2011
    16 Sep 2014 in reply to Nikola Zagorchev
    Link to this post

    Hi Nikola,

    That did the trick.

    Thanks -- Steve

  4. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    16 Sep 2014
    Link to this post
    Hi Steve,

    I am glad you have managed to filter the items and get those you want. Write back to us if we can help you further.

    Regards,
    Nikola Zagorchev
    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 posts, 0 answered