Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

How to save content while ignoring required properties?

Vote:
0

Hello everyone,

We have a custom service that can create draft content using the IContentRepository and some of the content properties are annotated with the [Required] attribute. The service does not always have the content required for those fields and a content editor has to add the missing content before publishing. 

We could use the approach described in the article below — however the problem is that the properties should still be required when the user creates content but not when it is created by our service.

https://www.david-tec.com/2017/07/hiding-required-properties-on-the-create-new-page-in-episerver/

Any advice?

#279450
Edited, Apr 29, 2022 5:57
Vote:
0

When doing it by code you can send in a SkipValidation flag

_contentRepository.Save(IContent, SaveAction.SkipValidation | SaveAction.Publish, AccessLevel.NoAccess);

That should skip the validation for the required attributes if I remember correctly

#279452
Apr 29, 2022 6:39
- Apr 29, 2022 7:05
Perfect, that'll do it. Thanks!
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.