8

I am working on some event system code and I have the following snippet of code to examine the PublishQueue and see if the current item I am scheduling is already scheduled:

public static bool IsInPublishingQueue(Session session, String tcmUri, Int32 state, Int32 action, DateTime date, PublicationTarget publicationTarget)
    {
        try
        {
            PublishTransactionsFilter filter = new PublishTransactionsFilter(session);

            filter.PublishTransactionState = PublishTransactionState.ScheduledForPublish;
            filter.StartDate = date;//Convert.ToDateTime("4/1/2013 1:46 PM");
            RepositoryLocalObject item = session.GetObject(tcmUri) as RepositoryLocalObject;
            filter.ForRepository = item.ContextRepository;

            if (publicationTarget != null)
            {
                filter.PublicationTarget = publicationTarget;
            }

            XmlElement element = PublishEngine.GetListPublishTransactions(filter);
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
            namespaceManager.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");

            //String xPath = String.Format("tcm:ListPublishTransactions/tcm:Item[@ItemID='{0}']", tcmUri);
            String xPath = String.Format("//*[@ItemID='{0}' and @State='{1}' and @Action={2}]", tcmUri, state, action);
            XmlNodeList nodeList = element.SelectNodes(xPath, namespaceManager);

            return nodeList.Count > 0;
        }
        catch (Exception ex)
        {
            throw new Exception("IsInPublishQueue Function Failed for Item with tcm: " + tcmUri + "Error: " + ex.Message);
        }
    }

The problem is that this results in an empty result set:

<tcm:ListPublishTransactions xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink" />

When I change it to the following I get back the set of items in the queue that match the Start date in my filter:

public static bool IsInPublishingQueue(Session session, String tcmUri, Int32 state, Int32 action, DateTime date, PublicationTarget publicationTarget)
    {
        try
        {
            PublishTransactionsFilter filter = new PublishTransactionsFilter(session);

            //filter.PublishTransactionState = PublishTransactionState.ScheduledForPublish;
            filter.StartDate = date;//Convert.ToDateTime("4/1/2013 1:46 PM");
            RepositoryLocalObject item = session.GetObject(tcmUri) as RepositoryLocalObject;
            filter.ForRepository = item.ContextRepository;

            if (publicationTarget != null)
            {
                filter.PublicationTarget = publicationTarget;
            }

            XmlElement element = PublishEngine.GetListPublishTransactions(filter);
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
            namespaceManager.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");

            //String xPath = String.Format("tcm:ListPublishTransactions/tcm:Item[@ItemID='{0}']", tcmUri);
            String xPath = String.Format("//*[@ItemID='{0}' and @State='{1}' and @Action={2}]", tcmUri, state, action);
            XmlNodeList nodeList = element.SelectNodes(xPath, namespaceManager);

            return nodeList.Count > 0;
        }
        catch (Exception ex)
        {
            throw new Exception("IsInPublishQueue Function Failed for Item with tcm: " + tcmUri + "Error: " + ex.Message);
        }
    }

This is the result set I get back which is what I expect:

<tcm:ListPublishTransactions xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink">
            <tcm:Item ID="tcm:0-1570-66560" Title="Article 2A" Publication="www.website.com" PublicationTarget="Staging" ItemType="16" ItemID="tcm:49-6009" ItemPath="\\www.website.com\\Building Blocks\\www.website.com" Action="1" State="0" StateChangeDate="2013-03-04T02:32:22" ScheduleDate="2013-04-01T13:46:19" UserId="tcm:0-13-65552" User="TestVM\\Administrator" Priority="4" Icon="T16L0P0" Managed="0" Allow="67133440" Deny="0" />
            <tcm:Item ID="tcm:0-1569-66560" Title="Article 1A" Publication="www.website.com" PublicationTarget="Staging" ItemType="16" ItemID="tcm:49-6008" ItemPath="\\www.website.com\\Building Blocks\\www.website.com" Action="1" State="0" StateChangeDate="2013-03-04T02:32:21" ScheduleDate="2013-04-01T13:46:19" UserId="tcm:0-13-65552" User="TestVM\\Administrator" Priority="4" Icon="T16L0P0" Managed="0" Allow="67133440" Deny="0" />
            <tcm:Item ID="tcm:0-1566-66560" Title="Article 2A" Publication="www.website.com" PublicationTarget="Staging" ItemType="16" ItemID="tcm:49-6009" ItemPath="\\www.website.com\\Building Blocks\\www.website.com" Action="0" State="0" StateChangeDate="2013-03-04T02:28:11" ScheduleDate="2013-04-01T13:46:19" UserId="tcm:0-13-65552" User="TestVM\\Administrator" Priority="4" Icon="T16L0P0" Managed="0" Allow="67133440" Deny="0" />
            <tcm:Item ID="tcm:0-1565-66560" Title="Article 1A" Publication="www.website.com" PublicationTarget="Staging" ItemType="16" ItemID="tcm:49-6008" ItemPath="\\www.website.com\\Building Blocks\\www.website.com" Action="0" State="0" StateChangeDate="2013-03-04T02:28:11" ScheduleDate="2013-04-01T13:46:19" UserId="tcm:0-13-65552" User="TestVM\\Administrator" Priority="4" Icon="T16L0P0" Managed="0" Allow="67133440" Deny="0" />

Any ideas why with the:

filter.PublishTransactionState = PublishTransactionState.ScheduledForPublish;

filter item the result set returns empty, when it should return the same result set as the second snippet of code which doesn’t have that filter option(the State=”0”, as seen above in bold is the indicator that the item is scheduled for publish)?

4

I ran into this a while ago and it ended up being a misunderstanding of what the date range meant when searching for scheduled transactions.

I think the issue was that when you set PublishTransactionState to ScheduledForPublish, the StartDate filter property applies to the date it was scheduled, instead of when it is meant to be published (or maybe it was the other way around, I've forgotten).

| improve this answer | |
  • Makes sense, thanks! The date that I am using is the actual date that it is schedlued for publish, which is when i want the publish action to happen. It seems for some reason not to acknolwedge the fact that I want the ScheduledForPublish state. – TridionNut Mar 5 '13 at 16:28
  • Sounds like you are running into the same issue then. You will only see transactions that were scheduled after the StartDate -- not ones that are schedules to be published after StartDate. – Peter Kjaer Mar 7 '13 at 9:15
3

This issue has been resolved in Tridion 2013.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.