Copied to clipboard

Flag this post as spam?

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


  • Paul Spinks 6 posts 97 karma points
    Sep 30, 2020 @ 15:37
    Paul Spinks
    0

    Csv Import using Content Service

    Goal:

    The ability to create/update records using CSV into Umbraco and other data sources in the future but for now just CSV.

    Problem:

    One of the document types I'm trying to import into has a dropdown list which doesn't like the text been stored.

    Found solution to that issue at https://our.umbraco.com/forum/umbraco-8/96101-umbraco-8-contentservice-and-dropdown-list#comment-306917

    Which doing JsonConvert.SerializeObject(new[] { "My Value" }); is totally fine but how would I know when to serialise the object for the property? How can I differentiate it from plain textbox etc?

    I'm getting a list of all the children from the parent like:

    var children = Umbraco.Content(parentGuid)?.Children ?? null;
    

    Once looping through the CSV rows then I'll check to see if I can find the child using:

    var request = contentService.GetById(foundChild.Id);
    

    Then I can use properties field from request to see if it's matches properties then call request.SetValue( ... )

    The only thing I can think of is to perform an if statement on the request.Properties.PropertyType.PropertyEditorAlias is equal to Umbraco.DropDown.Flexible and then serialise that.

    If you have a better solution, please let me know. Thanks.

  • Amir Khan 1282 posts 2739 karma points
    Sep 30, 2020 @ 20:05
    Amir Khan
    1

    Any reason not to use CMS Import? Will save you lots of trouble: https://our.umbraco.com/packages/developer-tools/cmsimport

  • Paul Spinks 6 posts 97 karma points
    Sep 30, 2020 @ 20:17
    Paul Spinks
    1

    The free version doesn't cover the updating records. It was amazing package but not in the budget though. Thanks for the suggestion.

Please Sign in or register to post replies

Write your reply to:

Draft