How can I get the date/time at which the item was last published in Tridion
Asked Answered
B

2

7

How can I get the date/time at which the item was last published.

I tried to create object for PublishInfoData inorder to use PublishedAt.

  PublishInfoData pobj = csClient.Read(pageTCMID, readoptions) as PublishInfoData;

But this gives error like cannot convert IdentifiableObjectData to PublishInfoData.

Please suggest.

Braeunig answered 23/10, 2012 at 14:42 Comment(0)
C
8

This will give you all publish info:

csClient.GetListPublishInfo(pageTCMID);

And then you have to select the latest:

var publishInfo = csClient.GetListPublishInfo(pageTCMID);
var lastPublishedAt = publishInfo.OrderByDescending(pi => pi.PublishedAt).First().PublishedAt;
Cranston answered 23/10, 2012 at 14:45 Comment(2)
Thanks for the reply. On trying this it says InvalidOperationException : Sequence contains no elements.Braeunig
That means that publishInfo.OrderByDescending(pi => pi.PublishedAt) didn't return anything and thus .First() then fails. Most likely your item hasn't been published yet.Clemenciaclemency
R
0

I add this Powershell code for the record to get the last published date of a page

Set-TridionCoreServiceSettings sdswpap004 2013-SP1
$client = Get-TridionCoreServiceClient

Write-Output "Getting the title"
$pageTitle = Get-TridionItem -Id "tcm:30-7386-64" | Select-Object Title
Write-Output $pageTitle

$publishInfo = $client.GetListPublishInfo("tcm:30-7386-64")



if ($publishInfo) {
    Write-Output "Getting the last pablished date: "
    Write-Output $publishInfo.PublishedAt | Out-String
}
Radiculitis answered 30/4, 2015 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.