Get Published Items Only - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Get Published Items Only

  • Get Published Items Only
  • 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

     

  • 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
     
  • 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
     
  • Hi Nikola,

    That did the trick.

    Thanks -- Steve