Copied to clipboard

Flag this post as spam?

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


  • Marc-André 51 posts 233 karma points
    Aug 19, 2019 @ 15:00
    Marc-André
    0

    Hi!

    Is there anyway to get a value from an unpublished node?

    Here's my code :

    public JsonResult<String> GetData()
        {
          var id = HttpContext.Current.Request­.QueryString["id"];
          dynamic properties = Umbraco.Content(Convert.ToInt32(id));
    
          return Json(properties.Data);
        }
    

    If I go to the BackOffice and chage the value of "Data" and just Save It, my method always return the last published version instead of my new saved, but unpublished one.

    Thanks!

  • Amir Khan 996 posts 2014 karma points
    Aug 19, 2019 @ 15:40
    Amir Khan
    100

    Would this work? I've used this to query for reviews tagged to unpublished locations, worked great for me.

    https://our.umbraco.com/forum/developers/api-questions/49595-Query-unpublished-nodes-by-property-value

    There's a check in the API to see if something is published, you could just filter for the opposite.

  • Marc-André 51 posts 233 karma points
    Aug 19, 2019 @ 15:47
    Marc-André
    0

    I tried it, but when I use the getValue method from the IContent returned by the query, it always return me null.

    That's said, I don't think it will see the difference between my published value and my saved value.

  • Marc-André 51 posts 233 karma points
    Aug 27, 2019 @ 11:47
    Marc-André
    0

    I finally get this to work with the API. Yeah!

  • SteveV 42 posts 202 karma points
    Aug 27, 2019 @ 12:11
    SteveV
    0

    Keep in mind if you use the ContentService you are talking directly to the database. This approach might not scale if your site receives a lot of visitors.

  • Marc-André 51 posts 233 karma points
    Aug 27, 2019 @ 12:12
    Marc-André
    0

    You're right! Is there a more performant way to do this?

Please Sign in or register to post replies

Write your reply to:

Draft