2

Has anyone else had any issues when trying to check the approval status of a component? I am using the code below, to check if a component meets the minimum approval status, before performing some logic.

Component component = (Component)engine.GetObject(new TcmUri(itemId, 
                                         itemType, publicationId));

if (component.ApprovalStatus == null 
      || engine.PublishingContext.PublicationTarget.MinApprovalStatus == null
      || component.ApprovalStatus.Position >= 
                engine.PublishingContext.PublicationTarget.MinApprovalStatus.Position)
{
    //some logic
}

However the code fails with the following error if I just run the code. (The line of code it actually fails on is the if statement).

EDIT: Forgot to mention the item doesn't meet the minimum approval status but should just perform the check and not go into the logic.

Item tcm:X-XXXX does not meet the minimum approval status

However this is not the case if I remote debug and actually inspect the variables individually when running through (if I don't inspect them it still fails)

I have tagged this as workflow as it's to do with approval status, didn't really know what else to tag it as. So sorry if this is wrong

  • In regards to your last point, are you actually doing workflow or using Approval Status for something else, like templating (I see you're using Engine, so suspecting the latter)? – Nickoli Roussakov Jun 9 '15 at 16:11
  • Hi Nickoli, I'm using it for templates rather than Workflow. Suppose that answers what I should have tagged it as. :-) – Matt Hill Jun 9 '15 at 21:40
3

During rendering (in particular: while publishing) the system performs an Approval Status check while loading items.

Your code triggers an implicit Component load on the component.ApprovalStatus property get and this will throw an exception if the Component doesn't meet the minimal Approval Status of the Publication Target.

It's unclear to me why you want to do an Approval Status check while rendering yourself (since the system already prevents rendering of anything that doesn't meet the minimal Approval Status).

| improve this answer | |
  • Hi Rick, Thanks for the answer. The reason I'm invoking this method myself that it is used for rendering our sitemap. At the moment it is failing to run as throws the exception anove. So thought I could loop through the iterations of the component until I hit one that has the required approval status. Think I can still achieve what I wanted to achieve within a try catch (which I was trying to avoid as they always feel like cheating). The thing that was throwing me was the fact that if I ran it through remote debugger it worked! – Matt Hill Jun 9 '15 at 21:38
  • Ah, I see, so you want to just skip Components that don't meet the minimal Approval Status. Indeed, that can be achieved using exception handling (just catch the specific exception type thrown in that case). That's not really cheating. – Rick Pannekoek Jun 10 '15 at 17:39

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.