Skip to content

Commit c009bdd

Browse files
renemadsenclaude
andcommitted
fix: template duplication — fix FieldGroup children + restore ReportH1-H5
Two bugs in the template duplicate flow (EFormService.CreateFields): 1. FieldGroup children were pre-assigned CheckListId but never got ParentFieldId set after the parent was created. The children were embedded in field.Children and implicitly saved by field.Create(), but without the correct ParentFieldId. Fix: detach children before creating the parent, then create each child separately with both CheckListId and ParentFieldId = field.Id set. 2. ReportH1-H5 were commented out in FindTemplates, so duplicated eforms silently lost their report headers. Uncommented. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a7a1300 commit c009bdd

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

eFormAPI/eFormAPI.Web/Services/EFormService.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,11 @@ private static async Task<CheckList> FindTemplates(int idEform, MicrotingDbConte
767767
JasperExportEnabled = x.JasperExportEnabled,
768768
DocxExportEnabled = x.DocxExportEnabled,
769769
ExcelExportEnabled = x.ExcelExportEnabled,
770-
//ReportH1 = x.ReportH1,
771-
//ReportH2 = x.ReportH2,
772-
//ReportH3 = x.ReportH3,
773-
//ReportH4 = x.ReportH4,
774-
//ReportH5 = x.ReportH5,
770+
ReportH1 = x.ReportH1,
771+
ReportH2 = x.ReportH2,
772+
ReportH3 = x.ReportH3,
773+
ReportH4 = x.ReportH4,
774+
ReportH5 = x.ReportH5,
775775
IsLocked = false,
776776
IsEditable = true,
777777
IsHidden = false,
@@ -940,15 +940,19 @@ private static async Task CreateFields(int eformId, MicrotingDbContext sdkDbCont
940940
foreach (var field in fieldsList)
941941
{
942942
field.CheckListId = eformId;
943-
if (field.FieldTypeId == fieldGroupTypeId)
943+
var children = field.Children?.ToList() ?? [];
944+
field.Children = [];
945+
await field.Create(sdkDbContext);
946+
947+
if (field.FieldTypeId == fieldGroupTypeId && children.Count > 0)
944948
{
945-
foreach (var fieldChild in field.Children)
949+
foreach (var child in children)
946950
{
947-
fieldChild.CheckListId = eformId;
951+
child.CheckListId = eformId;
952+
child.ParentFieldId = field.Id;
953+
await child.Create(sdkDbContext);
948954
}
949955
}
950-
951-
await field.Create(sdkDbContext);
952956
}
953957
}
954958

0 commit comments

Comments
 (0)