retrieve notice of the mandatory field from contentService
Hello Guys.
The topic might seem a bit odd, but let me explain: I'm creating a site where i need to be able to create some types of content from the frontend via the contentService API, and it works fine. Though, i would like to have the functionality as close to the umbraco backoffice as possible, and here comes the question about the mandatory field. ive created a news Document Type in umbraco, and made the bodyText field mandatory, but when i'm creating a news item and contentService.SaveAndPublishWithStatus('ContentItem') (without having bodyText filled with any data = complication with the mandatory setting on the bodyText property) I don't get an error or anything noticing that the Node isn't published, because of the missing values in the mandatory field. Though it is still saved!
- Is there any way i can get anything back from the API, wether it is giving me a notice about the not published item or preferably telling me which fields are missing ?
I could check the fields in my code, though i feel it is a bit redundant to keep logic two places instead of having umbraco take care of it, if it can.
Great question )
We have the same trouble, and we found solution.
Try to use .IsValid() method of Content object.
Returns a Bool indicating whether the content and its properties are valid. If a property is set to Mandatory and blank upon saving the Content is not considered valid. This check is used when Content is published, so it won't be possible to publish invalid Content.
//Given a ContentService object get Content by its Id and check if Content is valid
var content = contentService.GetById(1234);
bool valid = content.IsValid();
retrieve notice of the mandatory field from contentService
Hello Guys.
The topic might seem a bit odd, but let me explain:
I'm creating a site where i need to be able to create some types of content from the frontend via the contentService API, and it works fine. Though, i would like to have the functionality as close to the umbraco backoffice as possible, and here comes the question about the mandatory field.
ive created a news Document Type in umbraco, and made the bodyText field mandatory, but when i'm creating a news item and contentService.SaveAndPublishWithStatus('ContentItem') (without having bodyText filled with any data = complication with the mandatory setting on the bodyText property) I don't get an error or anything noticing that the Node isn't published, because of the missing values in the mandatory field. Though it is still saved!
- Is there any way i can get anything back from the API, wether it is giving me a notice about the not published item or preferably telling me which fields are missing ?
I could check the fields in my code, though i feel it is a bit redundant to keep logic two places instead of having umbraco take care of it, if it can.
thanks in advance!
Hi Nicolas,
Great question ) We have the same trouble, and we found solution.
Try to use .IsValid() method of Content object.
Returns a Bool indicating whether the content and its properties are valid. If a property is set to Mandatory and blank upon saving the Content is not considered valid. This check is used when Content is published, so it won't be possible to publish invalid Content.
//Given a
ContentService
object get Content by its Id and check if Content is valid var content = contentService.GetById(1234); bool valid = content.IsValid();http://our.umbraco.org/documentation/Reference/Management-v6/Models/Content
Thanks
is working on a reply...