What would be the best (most efficient) way to delete field descriptors that are being used by DOM instances? Is there a way to force it so that these are also being deleted from the instances?
The DOM Editor script gives the following error when trying to delete a field descriptor while DOM instances are using it: SectionDefinitionInUseByDomInstances.
Thanks in advance.
Hi Jason,
The DOM Editor is unfortunately not able to do this for you.
The simplest method would be to create an automation script that retrieves all instances and removes the field value:
foreach (DomInstance domInstance in domHelper.DomInstances.ReadAll())
{
domInstance.Sections
.FirstOrDefault(s => s.SectionDefinitionID.Equals(sectionDefinitionID))
?.RemoveFieldValueById(fieldDescriptorID);domHelper.DomInstances.Update(domInstance);
}
To make it more efficient, you could only retrieve the instances with that field.
But I don't know how to build that filter.
A filter to more efficiently retrieve the DomInstances that use that field could look like this:
var filter = new ANDFilterElement(DomInstanceExposers.SectionDefinitionIds.Contains(sectionDefinitionId.Id), DomInstanceExposers.FieldValues.KeyExists(fieldDescriptorId.Id.ToString()).Equal(true));
Far from being an expert on this – and it might depend the specific DOM but have you tried if you get the same message when the related elements (if any) are stopped?