Setting the values of a Multifield item

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:

Litium version: [7.1]

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

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?

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, it is easier to copy/past segments for verification.

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

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.

Here’s the example:

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);
}

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?

          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!

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

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?

        [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"));
        }

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

So the remaining issue is still with the UI?

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

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