private void WriteRecordToSection(IRecord record, Section section, DetailLevel detailLevel, RecordExtractToDocumentRequest request) { if (detailLevel == DetailLevel.CountsOnly) { return; } var primaryField = Service.GetPrimaryField(record.Type); var recordName = Service.GetFieldAsDisplayString(record, primaryField); var table = section.Add2ColumnTable(); table.AddFieldToTable(Service.GetFieldLabel(primaryField, record.Type), ExtractUtility.CheckStripFormatting(recordName, record.Type, primaryField)); if (detailLevel == DetailLevel.Names || request.OnlyDisplayName(record.Type)) { return; } var fields = Service.GetFields(record.Type).Intersect(record.GetFieldsInEntity()).ToArray(); if (fields.Any()) { var primaryKey = Service.GetPrimaryKey(record.Type); var actualFieldsToExclude = new List <string> { primaryField, primaryKey }; actualFieldsToExclude.AddRange(request.GetAllFieldsToExclude(record.Type)); foreach (var field in fields) { var fieldType = Service.GetFieldType(field, record.Type); if (fieldType == RecordFieldType.Uniqueidentifier) { actualFieldsToExclude.Add(field); } else if (Service.GetFieldType(field, record.Type) == RecordFieldType.String && new[] { TextFormat.PhoneticGuide, TextFormat.VersionNumber }.Contains( Service.GetFieldMetadata(field, record.Type).TextFormat)) { actualFieldsToExclude.Add(field); } if (field.EndsWith("_base") && fields.Contains(field.Left(field.Length - 5))) { actualFieldsToExclude.Add(field); } } var orderedFieldsToDisplay = fields .Where(f => !actualFieldsToExclude.Contains(f)) .OrderBy(f => Service.GetFieldLabel(f, record.Type)); foreach (var field in orderedFieldsToDisplay) { var label = Service.GetFieldLabel(field, record.Type); var display = Service.GetFieldAsDisplayString(record, field); if (request.StripHtmlTags && IsHtmlField(record.Type, field, request)) { display = display.StripHtml(); } if (!label.IsNullOrWhiteSpace() && !display.IsNullOrWhiteSpace() && !GetStringValuesToExclude().Contains(display)) { table.AddFieldToTable(label, display); } } } }