How to check whether current component is checkout as well as the user details who checkout using tridion coreservices

StackOverflow https://stackoverflow.com/questions/14266679

Question

I want to write small function to check whether passed Item Object is checkout in Tridion or not if yes then it will return "true" and also I want to get the details of user who has checkout the Item, using Tridion 2011 core services.

I know we have TryCheckout as well as Checkout in our CoreServiceClient but it returns Identifiable Object only.

Was it helpful?

Solution

You need to look at the LockType on the item. Consider doing something like this

SessionAwareCoreService2010Client client = new SessionAwareCoreService2010Client();
ComponentData data = (ComponentData)client.Read("tcm:300-85609", new ReadOptions());
FullVersionInfo info = (FullVersionInfo)data.VersionInfo;

The full version info contains all the info you need (i.e. CheckOutUser and LockType). LockType is an Enumeration defined by Tridion.ContentManager.Data.ContentManagement.LockType, and includes the following set of flags:

  • None - The item is not locked.
  • CheckedOut - The item is checked-out. This can mean either a temporary (edit) lock, a permanent lock (explicit check-out performed by user) or a workflow lock.
  • Permanent - The item is permanently checked-out, that is using an explicit check-out action.
  • NewItem - The item is a new item, that is it has been created, but not checked-in for the first time yet.
  • InWorkflow - The item is in a workflow.

OTHER TIPS

Below is the sample code to get the details of ItemCheckedout with Users details in it.

public static Dictionary<bool,string> ItemCheckedOutDetails(string ItemUri, CoreServiceClient client, ReadOptions readOpt, ItemType itemType)
{
    Dictionary<bool, string> itemDetails = null;
    FullVersionInfo itemInfo = null;
    if (itemType == ItemType.Component)
    {
        // reading the component data
        var itemData = (ComponentData)client.Read(ItemUri, readOpt);
        itemInfo = (FullVersionInfo)itemData.VersionInfo;
    }
    else if (itemType == ItemType.Page)
    {
        // reading the page data
        var itemData = (PageData)client.Read(ItemUri, readOpt);
        itemInfo = (FullVersionInfo)itemData.VersionInfo;
    }
    else if (itemType == ItemType.StructureGroup)
    {
        // reading the structuregroup data
        var itemData = (StructureGroupData)client.Read(ItemUri, readOpt);
        itemInfo = (FullVersionInfo)itemData.VersionInfo;
    }
    else if (itemType == ItemType.Publication)
    {
        // reading the Publication data
        var itemData = (PublicationData)client.Read(ItemUri, readOpt);
        itemInfo = (FullVersionInfo)itemData.VersionInfo;
    }
    else if (itemType == ItemType.ComponentTemplate)
    {
        // reading the component template data
        var itemData = (ComponentTemplateData)client.Read(ItemUri, readOpt);
        itemInfo = (FullVersionInfo)itemData.VersionInfo;
    }
    else if (itemType == ItemType.PageTemplate)
    {
        // reading the Page template data
        var itemData = (PageTemplateData)client.Read(ItemUri, readOpt);
        itemInfo = (FullVersionInfo)itemData.VersionInfo;
    }
    else if (itemType == ItemType.MultimediaType)
    {
        // reading the Multimedia Type data
        var itemData = (MultimediaTypeData)client.Read(ItemUri, readOpt);
        itemInfo = (FullVersionInfo)itemData.VersionInfo;
    }

    if (itemInfo != null)
    {
        if (itemInfo.LockType.Value == LockType.CheckedOut)
        {
            itemDetails.Add(true, itemInfo.CheckOutUser.Title);
        }
    }
    return itemDetails;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top