# Setting the values of a Multifield item

**URL:** <https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769>\
**Category:** Questions\
**Created:** [April 2, 2019, 9:27am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769 "2019-04-02T09:27:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![magnus.bolling](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/magnus.bolling/32/222_2.png) [@magnus.bolling](https://forum.litium.com/u/magnus.bolling)\
**Post date:** [April 2, 2019, 9:27am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/1 "2019-04-02T09:27:53Z")

</div>

Hey! I’ve been trying to set the values of a MultiFieldItem through one of my integrations. There are no errors being displayed and I can see that the assigned list/lists contains the right information. Here’s my code:

 ![](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/6bbb7c8944c1f72140e1da4af4dbcf78be7b2aff.png)

Litium version: _[7.1]_

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [April 2, 2019, 11:28am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/2 "2019-04-02T11:28:30Z")

</div>

Can you see the values in the db in Products.VariantFieldData?

Your problem sounds related to this bug in 7.1: [https://docs.litium.com/support/bugs/bug\_details?id=44951](https://docs.litium.com/support/bugs/bug_details?id=44951)

---

<div class="post-metadata">

**Author:** ![magnus.bolling](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/magnus.bolling/32/222_2.png) [@magnus.bolling](https://forum.litium.com/u/magnus.bolling)\
**Post date:** [April 2, 2019, 12:20pm UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/3 "2019-04-02T12:20:18Z")

</div>

Nope, nothing in that table. Looks quite likely that they would be related. Is there any way I can work around this at this time?

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 2, 2019, 12:56pm UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/4 "2019-04-02T12:56:23Z")

</div>

If you update with the API the database table should contains the information and your code above look correct. The linked bug is related to the UI in back office.

When you check the database table, the `FieldDefinitionId` column will contain the field name, the `ChildOwnerId` will contain the value from `NwpBasePpoductConstants.NwpGenericProperty`.

_Note: [Code can easy be attached as code block as text instead of an image](https://commonmark.org/help/), it is easier to copy/past segments for verification._

---

<div class="post-metadata">

**Author:** ![magnus.bolling](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/magnus.bolling/32/222_2.png) [@magnus.bolling](https://forum.litium.com/u/magnus.bolling)\
**Post date:** [April 3, 2019, 7:45am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/5 "2019-04-03T07:45:30Z")

</div>

You’re right. Not sure why I wasn’t seeing them before. Once again, is there anything I can do to fix this now?

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 3, 2019, 8:21am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/6 "2019-04-03T08:21:47Z")

</div>

Can you provide a running example that will show the issue? It seams to be an edge case; that we not cover with tests, if the data not is persisted.

---

<div class="post-metadata">

**Author:** ![magnus.bolling](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/magnus.bolling/32/222_2.png) [@magnus.bolling](https://forum.litium.com/u/magnus.bolling)\
**Post date:** [April 17, 2019, 12:45pm UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/7 "2019-04-17T12:45:15Z")

</div>

Here’s the example:

```auto
protected override void ProcessItem(Item item)
{
	var injectedList = new List<MultiFieldItem>();

	foreach(var attribute in item.NwpItem.Attributes)
	{
		var multiFieldItem = new MultiFieldItem();

		multiFieldItem.Fields.AddOrUpdateValue(NwpBaseProductConstants.NwpGenericLabel, attribute.Name);
		multiFieldItem.Fields.AddOrUpdateValue(NwpBaseProductConstants.NwpGenericValue, attribute.Value);

		injectedList.Add(multiFieldItem);
	}

	item.Variant.Fields.AddOrUpdateValue(NwpBaseProductConstants.NwpGenericProperty, injectedList);
	_variantService.Update(item.Variant);
}

```

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 17, 2019, 7:24pm UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/8 "2019-04-17T19:24:45Z")

</div>

The code example you provide is not executable without more information. Example the fields that you adding in the multi field, what is the field type and how is that fields configured?

---

<div class="post-metadata">

**Author:** ![wiirgy](https://avatars.discourse-cdn.com/v4/letter/w/e47c2d/32.png) [@wiirgy](https://forum.litium.com/u/wiirgy)\
**Post date:** [April 18, 2019, 9:32am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/9 "2019-04-18T09:32:23Z")

</div>

```auto
          new FieldDefinition<ProductArea>(NwpBaseProductConstants.NwpGenericLabel, SystemFieldTypeConstants.Text)
                {
                    CanBeGridColumn = true,
                    CanBeGridFilter = false,
                },
                new FieldDefinition<ProductArea>(NwpBaseProductConstants.NwpGenericValue, SystemFieldTypeConstants.Text)
                {
                    CanBeGridColumn = true,
                    CanBeGridFilter = false,
                },
                new FieldDefinition<ProductArea>(NwpBaseProductConstants.NwpGenericProperty, SystemFieldTypeConstants.MultiField)
                {
                    CanBeGridColumn = true,
                    CanBeGridFilter = false,
                    Option = new MultiFieldOption { IsArray = true, Fields = new List<string>(){ NwpBaseProductConstants.NwpGenericLabel, NwpBaseProductConstants.NwpGenericValue } }
                },

```

Here are my field definitions, hope this helps!

---

<div class="post-metadata">

**Author:** ![wiirgy](https://avatars.discourse-cdn.com/v4/letter/w/e47c2d/32.png) [@wiirgy](https://forum.litium.com/u/wiirgy)\
**Post date:** [April 18, 2019, 9:33am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/10 "2019-04-18T09:33:03Z")

</div>

It’s worth noting that I didn’t have an account at first so Magnus posted for me, but TS is originally me!

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 23, 2019, 8:33am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/11 "2019-04-23T08:33:30Z")

</div>

We have created a unit test as below code that I hope represent your code (more or less) and can not reproduce your issue.

What are we missing?

```auto
        [Fact]
        public void CheckMultiFieldForVariant()
        {
            var item = new Variant(this.UniqueString(), _baseProduct.SystemId);
            _variantService.Create(item);
            AddDisposable(() => _variantService.Delete(item));

            var fields = new List<FieldDefinition>
            {
                new FieldDefinition<ProductArea>("NwpGenericLabel", SystemFieldTypeConstants.Text)
                {
                    CanBeGridColumn = true,
                    CanBeGridFilter = false,
                },
                new FieldDefinition<ProductArea>("NwpGenericValue", SystemFieldTypeConstants.Text)
                {
                    CanBeGridColumn = true,
                    CanBeGridFilter = false,
                },
                new FieldDefinition<ProductArea>("NwpGenericProperty", SystemFieldTypeConstants.MultiField)
                {
                    CanBeGridColumn = true,
                    CanBeGridFilter = false,
                    Option = new MultiFieldOption
                    {
                        IsArray = true,
                        Fields = new List<string>() {"NwpGenericLabel", "NwpGenericValue"}
                    }
                }
            };

            foreach (var fieldDefinition in fields)
            {
                _fieldDefinitionService.Create(fieldDefinition);
                AddDisposable(() => _fieldDefinitionService.Delete(fieldDefinition));
            }
           
            var variant = _variantService.Get(item.SystemId).MakeWritableClone();
            var injectedList = new List<MultiFieldItem>();
            var attributes = new List<string>(){"One", "Two"};

            foreach (var attribute in attributes)
            {
                var multiFieldItem = new MultiFieldItem();
                multiFieldItem.Fields.AddOrUpdateValue("NwpGenericLabel", attribute);
                multiFieldItem.Fields.AddOrUpdateValue("NwpGenericValue", attribute + "Value");
                injectedList.Add(multiFieldItem);
            }

            variant.Fields.AddOrUpdateValue("NwpGenericProperty", injectedList);
            _variantService.Update(variant);
            var variantUpdated = _variantService.Get(item.SystemId);
            variantUpdated.Fields.TryGetValue("NwpGenericProperty", out var multiFieldValue);

            Assert.NotNull(multiFieldValue);
            var list = Assert.IsAssignableFrom<IList<MultiFieldItem>>(multiFieldValue);
            Assert.Equal(2, list.Count);
            Assert.Equal("One", list[0].Fields.GetValue<string>("NwpGenericLabel"));
            Assert.Equal("OneValue", list[0].Fields.GetValue<string>("NwpGenericValue"));

            Assert.Equal("Two", list[1].Fields.GetValue<string>("NwpGenericLabel"));
            Assert.Equal("TwoValue", list[1].Fields.GetValue<string>("NwpGenericValue"));
        }

```

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [April 23, 2019, 8:39am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/12 "2019-04-23T08:39:52Z")

</div>

The data did show up in the table in the end, though? See quote below.

> [@magnus.bolling](#):
>
> You’re right. Not sure why I wasn’t seeing them before.

So the remaining issue is still with the UI?

---

<div class="post-metadata">

**Author:** ![wiirgy](https://avatars.discourse-cdn.com/v4/letter/w/e47c2d/32.png) [@wiirgy](https://forum.litium.com/u/wiirgy)\
**Post date:** [May 6, 2019, 6:25am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/13 "2019-05-06T06:25:50Z")

</div>

Yes, it did show up in the table. But wasn’t shown in the UI.

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [May 6, 2019, 6:40am UTC](https://forum.litium.com/t/setting-the-values-of-a-multifield-item/769/14 "2019-05-06T06:40:17Z")

</div>

The UI bug was fixed in the latest release 7.2:  
[https://docs.litium.com/documentation/release-notes](https://docs.litium.com/documentation/release-notes)
