4

I have some items in publishing queue in schedule for deployment state. I want to abort some of those transaction on the basis of Id of the items using Tridion Core service API. I want to remove items from queue as well.

  • Have you tried to use client.Delete(transactionId)? If the UI can do it, the API can do it. – Nuno Linhares Jul 15 '13 at 13:55
  • Nuno is right. It will delete queue message as well. – Syav4eg Jul 15 '13 at 14:48
4

This will not work if the Transaction already started being processed (just like it happens with deleting a transaction in the UI), so what you can achieve is to remove the transaction from the queue.

If it happens before the publisher picked up work, then you'll be fine. However, if the publisher already started working on this job then you will be too late to stop it and only a template or deployment error could abort publishing.

Anyway, you could use something along these lines of code to get you what you need (note: I didn't test this code)

PublishTransactionsFilterData filter = new PublishTransactionsFilterData
    {
        PublishTransactionState = PublishTransactionState.ScheduledForPublish
    };

List<string> transactionsToDelete = new List<string>();
foreach (PublishTransactionData transaction in client.GetSystemWideList(filter))
{
    foreach (LinkToIdentifiableObjectData linkToItem in transaction.Items)
    {
        if(linkToItem.IdRef == idOfItemToRemove)
            transactionsToDelete.Add(transaction.Id);
    }
}
foreach (string transactionId in transactionsToDelete)
{
    client.Delete(transactionId);
}

EDIT

Too complicated to answer in a comment.

Prior to Tridion 2013, not all GetSystemWideList methods will return *Data objects and instead you need to rely on the GetSystemWideListXml method. The following code could be used to achieve the same functionality as above on Tridion 2011 SP1:

foreach (XElement transactionXml in client.GetSystemWideListXml(filter).Nodes())
{
    PublishTransactionData data = (PublishTransactionData)client.Read(transactionXml.Attribute("ID").Value, new ReadOptions());
    foreach (LinkToIdentifiableObjectData linkToItem in data.Items)
    {
        if (linkToItem.IdRef == "tcm:1-2-3")
            transactionsToDelete.Add(data.Id);
    }
    // OR - instead of going to the server again to load the Data
    // Just read it directly from the Xml
    if(transactionXml.Attribute("ItemID").Value.Equals("tcm:1-2-3"))
        transactionsToDelete.Add(transactionXml.Attribute("ID").Value);
}
| improve this answer | |
  • Nuno, I had scheduled an item for publish using core service I set property "DeployAt", On setting the value of this property item goes to "ScheduledForDeployment" State. If I get the way to make the item "ScheduleForPublish" Using Core service then my problem will be resolved. Can you please help me to make the Item "ScheduleForPublish" using core service – AlokBhatt Jul 15 '13 at 15:56
  • Use PublishInstructionData.StartAt instead of .DeployAt – Nuno Linhares Jul 15 '13 at 16:04
  • Yes I figured that out, Thanks. Is there any way for forcing the scheduled item to publish before scheduled time? – AlokBhatt Jul 15 '13 at 16:13
  • Give it a try - you could try loading the transaction, modifying the start date, then save it back with client.Update. If that fails, create a new transaction with a different start time, then delete the old one. – Nuno Linhares Jul 15 '13 at 16:27
  • While Debugging I Found that When I am fetching failed transactions it is working fine, But in case of transaction scheduled for publish I am not getting any transactions using client.GetSystemWideList(filter). Is there any problem with Tridion 2011 SP1? – AlokBhatt Jul 15 '13 at 16:29
2

You can delete a transaction, I tested it before and client.Delete(transactionId) works. I would be careful removing transactions which are not processed (either Success or Failed) yet as you could run in a situation where you remove an item while the publisher was just about to publish it.

Have a look at PublishTransactionData.State, it will be PublishTransactionState.ScheduledForPublish in your case.

| improve this answer | |
  • Oh, misread Nuno's answer, he already explains about the PublishTransactionData.State. – Jan H Jul 15 '13 at 15:53

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.