Search code examples
c#tridiontridion2009

Tridion 2009 - Using Interops - Is there a possibility to add multiple setConditions for the same Name


Am stuck with small problem.

I want to add multiple setConditions for the same Name that is for PublicationTarget. This is using interops dll.

ListRowFilter rowFilter = mTDSE.CreateListRowFilter();
rowFilter.SetCondition("StartDate", sDate);
rowFilter.SetCondition("EndDate", eDate);
rowFilter.SetCondition("PublicationTarget", pubStgTarget);

For this PublicationTarget, I want to filter with staging & live target and I tried all the ways but no use.

rowFilter.SetCondition("PublicationTarget", pubStgTarget);

Please suggest,
1. Passing xis possible, what is the best way to achieve?

I tried this ways but no luck;-

rowFilter.SetCondition("PublicationTarget", "tcm:0-1-65537"); // Gives only staging
rowFilter.SetCondition("PublicationTarget", "tcm:0-2-65537"); // Gives only Live
rowFilter.SetCondition("PublicationTarget", "tcm:0-1-65537|tcm:0-1-65537"); // No result
rowFilter.SetCondition("PublicationTarget", oPubList); // No result - `oPubList` is a 

List<string>


Solution

  • Nope, it is not possible unfortunately. If you want to put a condition on PublicationTarget, it must be to only one PublicationTarget.

    However there are 2 workarounds:

    1. Create two RowFilters and set a different PublicationTarget condition in each of them. Then you would issue the query twice (once for each filter). This means you would need to process 2 XML result nodes.

    2. Don't use a PublicationTarget condition when performing the GetListPublishTransactions(). You will then get back an XML element that contains records for all PublicationTargets. In your code, you will filter only those that are of interest to you (e.g. Staging or Live).

    I would probably use #2 (unless I know the Publish Queue could potentially return a very large number of records, in which case, I would use #1).

    Sample code for #2:

    tdse = new TDS.TDSEClass();
    tdse.Impersonate(user.Title);
    tdse.Initialize();
    
    mgtInfo = tdse.GetManagementInfo();
    filter = tdse.CreateListRowFilter();
    
    filter.SetCondition("InfoType", 2); // InProgress
    filter.SetCondition("Publication", "tcm:0-23-1");
    
    XmlDocument dom = new XmlDocument();
    dom.LoadXml(mgtInfo.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[@PublicationTarget='{0}'] | " +
        "tcm:ListPublishTransactions/tcm:Item[@PublicationTarget='{1}']",
        stagingTcmUri, liveTcmUri);
    XmlNodeList nodeList = dom.SelectNodes(xPath, namespaceManager);
    
    foreach (XmlNode node in dom.DocumentElement.ChildNodes) {
        //do your thing
    }
    

    Note: double check the XPath expression, I haven't actually tested that bit.