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

Forums / Developing with Sitefinity / Question about IContent and workflow

Question about IContent and workflow

4 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    23 Jul 2010
    Link to this post
    Hi,

    When I enable workflow for news items, I need only published items. The following line of code is also showing 'Declined' items:

    items = contentManager.GetContent(startIndex, this.ItemsPerPage, "Publication_Date ASC", ContentStatus.Published, info);

    I suppose I need "ApprovalStatus.Published', but the 'GetContent' function doesn't accept this.
    How can I achieve only Published news items?

    Regards,
    Daniel
  2. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    23 Jul 2010
    Link to this post
    Hi Daniel,

    This will work for your case:

    var contentManager = new ContentManager("News");
     
    IList AllItems = contentManager.GetContent();
     
    HttpContext.Current.Response.Write("News Items with status: Published <br/>");
    foreach (IContent cnt in AllItems)
    {
        StagedContent stgCnt = contentManager.GetStagedContent(cnt.ID) as StagedContent;
        if (stgCnt != null)
        {
            WorkflowInstance workflow;
            workflow = WorkflowRuntime.Instance.GetWorkflow(stgCnt.WorkflowInstanceId);
            if (workflow != null)
            {
                ContentWorkflow activity = (ContentWorkflow)workflow.Activity;
                if (activity.ApprovalStatus == ApprovalStatus.Published)
                    HttpContext.Current.Response.Write("  <strong>" + cnt.GetMetaData("Title").ToString() + "</strong><br/>");
            }
        }
    }


    Best,

    G
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Jul 2010
    Link to this post
    Hi George ,

    You have to get the current state - GetCurrentState not the staged content which may lock the item.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    23 Jul 2010
    Link to this post
    Okay, thanks. I saw this post, but I wondered if there wasn't an easier way. Seems not. This will work.

    Regards,
    Daniel
Register for webinar
4 posts, 0 answered