1

We are Using DD4T.ContentModel for Retriving Component info.

We are able to get Component ID, Component Name and Revision Data from DD4T.ViewModel.Atributes. But As per requirement we need Blueprint and Last Modified User Details of Respective Component as well. can you please help me how to get the details.

Component Blueprinting status (Name of the publication where the item originates if it hasn't been localized, or the name of the publication where it has been localized - with (local copy) added if it's localized)

Last Edited date: yyyy-mm-dd

Last Edited by: Username

1
  • Welcome to Tridion Stack Exchange, Chandana. Not to challenge the requirements too much, but I usually recommend content fields for things like edited date and author, since these can be changed by system actions like content porting. See createandbreak.net/2013/08/…. Commented Aug 5, 2021 at 15:27

1 Answer 1

5

Content Delivery does not expose all of the component's properties. So, the Content Delivery frameworks, DD4T and DXA, would not contain all of the component's properties that you would normally see in the Content Manager. Using DD4T, we would be able to get the component's publication information. Something like this:

var componentFactory = DependencyResolver.Current.GetService<IComponentFactory>();
IComponent component = componentFactory.GetComponent("tcm:xx-xxx");
string owningPublicationTitle = component.OwningPublication.Title;
string contextPublicationTitle =  component.Publication.Title;

To get the other component properties, the best approach would be to expose a REST endpoint that uses the Core Service API to get the component properties. And in the DD4T application, just consume the REST endpoint to grab the component properties. Something like this should work:

[HttpGet]
[Route("GetComponentInfo")]
public async Task<ActionResult<object>> GetComponentInfo()
{
    try
    {
        CoreServiceClient client = new CoreServiceClient();
        ComponentData componentData = (ComponentData) await client.ReadAsync("tcm:xx-xxx", null);
        FullVersionInfo fullVersionInfo = (FullVersionInfo)componentData.VersionInfo;
        string lastEditedDate = fullVersionInfo.RevisionDate.Value.Date.ToLongDateString();
        string lastEditedBy = fullVersionInfo.Revisor.Title;
      
        return new
        {
            LastEditedDate = lastEditedDate,
            LastEditedBy = lastEditedBy
        };
    }
    catch (Exception)
    {
        return this.StatusCode(StatusCodes.Status500InternalServerError, "Issues connecting to Tridion");
    }
}

It would be interesting to see the use case for this.

3
  • 1
    Note that using this approach would likely result in syncing issues between published data in Content Delivery and Content Manager. For instance, if a component is published with a LastEditedDate, then updated in the CM (but not republished), this would result in a LastEditedDate that corresponds to the last edits in the CM, NOT the last edits that have been published. Commented Aug 4, 2021 at 21:26
  • I'm able to get Dynamic Components Publication info but i'm getting error while retriving Normal Components (Published Embedded as page) Publication info. can you please help me.
    – Ajay
    Commented Aug 24, 2021 at 10:23
  • Normal components can not be queried like that. They have to be published as a DCP. Components (Published Embedded as Page) would only be available as part of the page content. Commented Aug 26, 2021 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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