Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

Below is my code for checking if a page is checked out using core service. My code is running with MTS user. I have checked out the page and the condition is getting evaluated to true but once the execution reached client.UndoCheckout() method call, it is giving an exception stating

Item is not checked-out

I went back and checked in CME and the page was still checked out. Am I missing something, because this is very weird?

try
{
  PageData pageData = client.TryCheckOut("tcm:18-8339-64", new ReadOptions()) as PageData;
  if (((pageData.VersionInfo) as FullVersionInfo).LockType == LockType.CheckedOut)
  {
    client.UndoCheckOut(pageData.Id, false, null);
  }
}
catch(Exception ex)
{
  Console.write("ERROR:"+ex.Message); 
}

Update:

I have even tried below and getting the same exception.

if (!pageData.IsEditable.Value)
{
  client.UndoCheckOut(pageData.Id,true,null);
}
share|improve this question
    
Can you add a check to print out the AllowedActions to the console? What are these values? –  Dylan .. Mark Saunders Mar 4 at 11:32
add comment

2 Answers 2

It might be transaction problem, for debug, try to wait for a second or two before doing UndoCheckOut.

May I ask you why are you trying to do this? You can read the page and check LockType if it's CheckedOut, or if you want to check if current user can checkeout item you can take a look at AllowedActions

share|improve this answer
    
Updated the code –  Kris Mar 3 at 8:21
add comment

First of all your code should work. its strange you are getting the error.

a question:

If you are doing un-do check out for the page, why are you checking out using TryCheckOut? Because in this case

if (((pageData.VersionInfo) as FullVersionInfo).LockType == LockType.CheckedOut)

it will always return to true.

I think you should use Read to read the page. And then un-do checkout if it is already checked out.

please try below code:

        PageData pageData = tridionClient.Read("tcm:tcm:18-8339-64", new ReadOptions()) as PageData;

        if (((pageData.VersionInfo) as FullVersionInfo).LockType == LockType.CheckedOut)
        {
            tridionClient.UndoCheckOut(pageData.Id, false, null);
        }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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