Copied to clipboard

Flag this post as spam?

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

  • andrew shearer 349 posts 444 karma points
    Oct 11, 2018 @ 03:37
    andrew shearer

    programmatically updating content in NestedContent by type


    Does anybody have a convenient way of using the content service API to update content that resides in a NestedContent property?

    For example, say that a “Widget” doctype has been used to content load 100 pages in the website via NestedContent, how would you go about programmatically identifying the pages that use this Widget doctype in the NestedContent property so that you could then update a value within the Widget?

    The ContentService GetContentOfContentType doesn’t do this.


  • Søren Kottal 396 posts 2389 karma points MVP c-trib
    Oct 11, 2018 @ 07:02
    Søren Kottal

    Hi Andrew

    You need to generate the JSON blob required by Nested Content yourself. It should be an array of objects, and each object must have the properties key, ncContentTypeAlias, and the properties of your desired document type.

    I have previously done like this

    var contentItem = ContentService.GetById(1);
    var nestedContentValue = new JArray();
    // you can add a loop here, if you need multiple nested items
    var nestedContentItem = new JObject();
    // you need to add a Guid as a key to your item
    nestedContentItem .Add("key", Guid.NewGuid().ToString());
    // and the desired doctype
    nestedContentItem.Add("ncContentTypeAlias", "myNestedType");
    // add the values for each property of your doctype
    nestedContentItem.Add("myPropertyAlias", "some property value");
    // finally, add you nestedContentItem, to your nestedContentValue
    // then set the value of your IContent contentItem
    contentItem.SetValue("nestedContentProperty", JsonConvert.SerializeObject(nestedContentValue));

    Hope it helps :)

  • andrew shearer 349 posts 444 karma points
    Oct 11, 2018 @ 19:24
    andrew shearer

    thanks Søren :D

    i was just as interested to know how i should identify pages that contain the said doctype in their NestedContent property (your first line of code). Does anyone know convenient/efficient ways of doing that? thank you

Please Sign in or register to post replies

Write your reply to: