MutliField add/delete fields by code

Hi!

When modifying (adding/removing) fields from the MultiField (by code), I allways have to add/remove the Multifield in the BackOffice in order for it to appear. Is it to possible to update a MultiField by code?

I usually solve it by deleting the MultiField from the Backoffice and then build the solution…or go info the backoffice (manually update)…But it’s a struggle when having multiple environments.

Thankful for any answers :slight_smile:

Litium version: 7.4.2

Standard behavior is that templates and fields defined in code are only created/updated during startup if they are new (read more).

You can modify DefinitionSetup.InitFields() to always update fields from code on startup, will require adding a call to _fieldDefinitionService.Update()

I have only tested this with templates myself and not with fields so I hope it works, try it out and post here on how it goes.

Thanks for the input.

Unfortunately it did not work. Added following line in the InitFields() function.
_fieldDefinitionService.Update(currentField);

Did Build and Rebuild the solution

Did you also remove the check if the field was already created?

If you mean this one, then yes:

if (IsAlreadyExecuted(item.Id, item.AreaType.Name))
{
//continue;
}

Noticed that you seem to be updating using the old field and not your new definition, try changing to:

item.SystemId = currentField.SystemId;
_fieldDefinitionService.Update(item);

Thanks marten, that did the job :slight_smile:

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.