Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 954 karma points
    Mar 20, 2014 @ 06:06
    Tom
    0

    ContentService SetValue on a textfield property type failing

    Hi I have an instance IContent with a propertyalias of metaDescription.

     

    In the content service I'm calling content.SetValue("metaDescription", "test");

    and then calling ServiceContext.ContentService.SaveAndPublishWithStatus(content)

     

    The result is coming back with Umbraco.Core.Publishing.PublishStatusType.FailedContentInvalid

    when I'm inserting a string in to a textfield..

    Just wondering if this was a legitimate bug?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 20, 2014 @ 10:12
    Jan Skovgaard
    0

    Hi Tom

    What version of Umbraco are you using? is it 6 or 7?

    And have you consulted the documentation on using the contentservice here http://our.umbraco.org/documentation/Reference/Management-v6/Services/?

    If so...could you perhaps show your code so it's a lot easier for people to help you out?

    Looking forward to hearing from you.

    Cheers,
    Jan 

  • Tom 713 posts 954 karma points
    Mar 20, 2014 @ 23:55
    Tom
    0

    Hi Jan,

    Thanks for the reply.

    I'm just trying to populate the above field with a propertyAlias of metaDescription. The code below we have working with a site running v6 and it works perfectly.

    I'm using V7 and the code is here:

       public void SetPropertyOnContent(IContent content, string propertyAlias, string value)
            {
                content.SetValue(propertyAlias, value);
                SaveAndPublishIfAppropriate(content);
            }
    
            void SaveAndPublishIfAppropriate(IContent content)
            {
                if (content.Published)
                {
                    var publishAttempt = ServiceContext.ContentService.SaveAndPublishWithStatus(content);
    
                    if (publishAttempt.Success)
                    {
                        Console.WriteLine("Successfully published node with id {0}", content.Id);
                    }
                    else
                    {
                        throw new InvalidOperationException("Failed to publish node with id " + content.Id);
                    }
                }
                else
                {
                    ServiceContext.ContentService.Save(content);
                    Console.WriteLine("Successfully saved unpublished node with id {0}", content.Id);
                }
            }
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 21, 2014 @ 00:15
    Jan Skovgaard
    0

    Hi Tom

    I think this may be a bug since the big thing in v7 is the new ui + improvements of the installer and other things. Don't think there should be any changes to the underlying API. I could be wrong but I think it's a good idea to file a bug report at http://issues.umbraco.org/issues.

    Cheers,
    Jan 

  • Tom 713 posts 954 karma points
    Mar 21, 2014 @ 04:34
    Tom
    0

    Thanks Jan will do.

Please Sign in or register to post replies

Write your reply to:

Draft