2

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);
}
1
  • Can you add a check to print out the AllowedActions to the console? What are these values? – Dylan .. Mark Saunders Mar 4 '14 at 11:32
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

1
  • Updated the code – Guest19876 Mar 3 '14 at 8:21
1

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);
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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