Copied to clipboard

Flag this post as spam?

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


  • Mubeen 15 posts 126 karma points
    Feb 08, 2021 @ 15:16
    Mubeen
    0

    Proper way to set value of a property of type Nested Content programmatically

    I have a nested content property that i am trying to modify programmatically. Following is my code:

    var nestedStr = linkedContent.GetValue<string>("linkedElements");
    var nestedResult = nestedStr == null ? new List<RootObject>() : JsonConvert.DeserializeObject<List<RootObject>>(nestedStr);
    var obj = new RootObject()
    {
         name = node.Name,
         ncContentTypeAlias = link.ncContentTypeAlias,
         relationType = type,
         linkedElement = JsonConvert.SerializeObject(lst),
         statement = link.GetPropertyValue<string>("statement")
     };
     nestedResult.Add(obj);
     nestedStr = JsonConvert.SerializeObject(nestedResult);
     if (isNew)
     {
         linkedContent.SetValue("linkedElements", nestedStr);
         sender.SaveAndPublishWithStatus(linkedContent);
     } 
    

    This is all working fine but when i save the linkedContent it's not reflecting on the website. I have to go to the backend and "Save and Publish" it manually then everything works fine.

    Maybe it's because i am creating my own objects and in process missing a lot of inherited properties while updating the nested content property. Please can someone point me to the right direction?

Please Sign in or register to post replies

Write your reply to:

Draft