Copied to clipboard

Flag this post as spam?

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


  • AndrewMorgun 10 posts 87 karma points
    Jun 22, 2021 @ 08:13
    AndrewMorgun
    0

    Create Dictionary item from code

    Hi! How can I create dictionary item from code?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 22, 2021 @ 08:44
    Dan Diplo
    100

    You'd use the LocalisationService and call the CreateDictionaryItemWithIdentity() method to programmatically create a dictionary item.

  • AndrewMorgun 10 posts 87 karma points
    Jun 22, 2021 @ 08:51
    AndrewMorgun
    0

    Thank you for the answer!! I see that there must be a parentId in the CreateDictionaryItemWithIdentity method, where can I get this?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 22, 2021 @ 09:49
    Dan Diplo
    0

    Hi! So the signature to the CreateDictionaryItemWithIdentity method looks like this:

    CreateDictionaryItemWithIdentity(string key, Guid? parentId, string defaultValue = null)

    So I believe that the parentId can be null if you want to create the dictionary item within the root of the dictionary area. However, if you want to nest the item under an existing dictionary item, then you'd need to pass the parent ID as a GUID.

    You can get the IDs of the root items by calling LocalizationService.GetRootDictionaryItems() which returns all the root items. Each item will have a property called Key which is the GUID you need to pass as the parent to create a child item.

  • AndrewMorgun 10 posts 87 karma points
    Jun 22, 2021 @ 09:53
    AndrewMorgun
    0

    Many thanks

Please Sign in or register to post replies

Write your reply to:

Draft