Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Niclas Schumacher 67 posts 87 karma points
    Jan 15, 2014 @ 10:31
    Niclas Schumacher
    0

    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!

     

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Nov 13, 2014 @ 11:48
    Alex Skrypnyk
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft