Programatically creating a ContentApprovalDefinition for a block

Vote:
 

Hi,

I'm trying to create a ContentApprovalDefinition when creating a block. This is done to be able to exclude some specific block types from the content approval process. 

I'm using the following code from an init module on its CreatedContent event: 

...

definition = new ContentApprovalDefinition()
{
   ContentLink = e.ContentLink,
   Steps = GetApprovalSteps()
};

var clone = definition.CreateWritableClone();

approvalDefinitionRepository.SaveAsync(clone).Wait();

but it gives me the following exception when saving the clone:

ApprovalDefinitionOperationException: Not allowed to create a ContentApprovalDefinition on an item inside a content folder

Any ideas why it is not allowed for blocks to create a definition, or if there's any way to allow it? (It works just fine using pages)

#223691
Edited, Jun 02, 2020 15:03
Vote:
 

Hi Sanjay,

Thanks for your answer!

Unfortunately, I couldn't get that solution to work for blocks. I still get the same exception, even if the block has been published.

And in the case linked above, the user wanted the image to be published on create which is not what I want. The content should still be unpublished after creating it, but ready to be set to status "RequestingApproval" if the block is of a specific type.

Any other ideas?

Thanks!

#223740
Jun 03, 2020 11:17
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.