Copied to clipboard

Flag this post as spam?

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


  • Sprite 18 posts 158 karma points
    Sep 26, 2023 @ 13:52
    Sprite
    0

    Checkboxlist add prevalue from code

    Hi,

    I have document type that uses a checkbox list with some predefined values.

    We use an importer to import data into these documenttypes and map to the predefined values.

    If a predefined value does not exest I want to add it before we map it.

    How can I get all the options/prevalues for the checkboxlist? and how can we add a new option/prevalue to the list?

    Hope somebody can point me in the right direction.

  • Sprite 18 posts 158 karma points
    Sep 28, 2023 @ 08:50
    Sprite
    100

    I figured it out. This seems to do the job

     private IDataTypeService _dataTypeService;
    
        public fieldProviderDropdown(IDataTypeService dataTypeService)
        {
            _dataTypeService = dataTypeService;
        }
    

    inside the function:

      var dataType = _dataTypeService.GetDataType("Regios List");                
    
                    ValueListConfiguration prevalues = (ValueListConfiguration)dataType.Configuration;
    
                    ValueListConfiguration.ValueListItem itemtest = new ValueListConfiguration.ValueListItem();
    
                      itemtest.Value = value.ToString();
                      itemtest.Id = prevalues.Items.Count+1;
                      prevalues.Items.Add(itemtest);
                      _dataTypeService.Save(dataType);
    
Please Sign in or register to post replies

Write your reply to:

Draft