When doing a 'View on Site' from a Component in Tridion 8.5, the popup dialogue gives a list of pages that the the component has been published on (along with the Purposes):

enter image description here

I can see from Fiddler that this makes the following API call:

POST /WebUI/Models/TCM54/Services/Publishing.svc/GetListContainingPages HTTP/1.1

with the content:

{"id":"tcm:1135-11570","instruction":{"includeWorkflow":true,"resolvePublishedPagesOnly":true}}

and get the response similar to:

{
    "d": "<tcm:ContainingPages xmlns:tcm=\"http:\/\/www.tridion.com\/ContentManager\/5.0\" ID=\"tcm:1135-11570\">
        <tcm:Item ID=\"tcm:1135-11565-64\" Title=\"Homepage\" Path=\"\\400 Website\\Home\">
        <tcm:PublishTarget TargetTypeId=\"tcm:0-1005-65538\" TargetTypeTitle=\"Staging\" 
        Purpose=\"Staging\" IsPublished=\"true\" PublishedAt=\"2018-07-10T14:25:27\" \/>
        <\/tcm:Item>
        <\/tcm:ContainingPages>"
}

I would like to emulate this behaviour in a Core Service app.

Can this be done through the Core Service API? If so, how is this achieved?

I’ve tried using Client.GetPublishUrl(ItemId, Purpose); but this only works with Pages, Structure Groups and Publications.

I've also tried Client.GetListPublishInfo(ComponentId);, but this only gives details if the Component is published as part of a Dynamic Component Presentation.

NOTE: I could obviously do this by recursively doing a 'Where used' on the Component(s) until I get a list of Pages and then seeing whether they're published, but was hoping that there was a simpler mechanism.


Update:

Here is the working code based on the accepted answer that Neil gave:

void Main() {
    ResolveContainingPagesInstructionData instruction = new ResolveContainingPagesInstructionData() {
        IncludeComponentMetadataLinks = true,
        IncludeDynamicVersion = true,
        IncludePageMetadataLinks = true,
        IncludeWorkflow = true,
        ResolvePublishedPagesOnly = true
    };

    ContainingPagesDictionary dictionary = Client.ResolveContainingPages("tcm:1135-11570", instruction);
    dictionary.Dump();

    foreach (var key in dictionary.Keys.OrderBy(k => k.Item.Title))
    {
        string publishUrl = Client.GetPublishUrl(key.Item.IdRef, "Staging");
        Console.WriteLine($"{key.Item.Title} ({key.Item.IdRef}) - {publishUrl}");
    }
}
up vote 6 down vote accepted

Jon,

I believe under the covers that the Core Service method ResolveContainingPages is used:

ContainingPagesDictionary ResolveContainingPages(
    string componentId,
    ResolveContainingPagesInstructionData instruction
)

componentId

  • Type: System.String
  • TCM URI or WebDAV URL of a component.

instruction

  • Type: Tridion.ContentManager.Data.ContentManagement.ResolveContainingPagesInstructionData
  • An instance of ResolveContainingPagesInstructionData with set of options that configure resolving.

Returns a set of pages where component is directly or indirectly (via component links) used. If page is published, the associated set of publish info is also returned (one PublishInfoData instance per publish destination).

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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