Start content approval process for new content only

Vote:
 

Hi,

I'm programmatically creating and updating content and want to start the content approval process, if one exists for the content, for newly created content only. For existing content, I want the changes to be published immediately.

I want to achieve this without putting in additional conditional code to check whether the content is new or existing and then use either SaveAction.RequestApproval or SaveAction.Published accordingly.

Can I just use SaveAction.Default to handle the above use case for both new and existing content? According to the documentation, SaveAction.Default "Saves a version maintaining the current status" - https://world.episerver.com/documentation/developer-guides/CMS/Content/content-versions/

Does this mean that if there is an approval definition, it will save any new content in AwaitingApproval status and start the approval process while maintaining the Published status for saving existing content?

Appreciate any advice or suggestions

Thanks

#258852
Jul 13, 2021 0:52
Vote:
 

Hi Ron,

SaveAction.Default creates a new version of the content so if there is a content approval workflow configured, i believe that it will go through the workflow.

SaveAction.Publish will work fine if you want to update content already published. It will not trigger the workflow.

Note that you may get an error if you attempt to programatically update content already going through a content approval workflow. For this case, consider using SaveAction.Patch (only if you are ok with updating the current version of the content)

Thanks

#258861
Jul 13, 2021 16:01
* 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.