---
id: object/codeunit/5051
type: object
title: Codeunit 5051 "SegManagement"
summary: Codeunit 5051 "SegManagement" in Base Application (Microsoft.CRM.Segment). 9 public procedures, 42 events. Present since at least BC23, still in BC30, changed in BC24-26.
tier: official
language: en
tags:
  - codeunit
  - base application
versions:
  introduced: null
  last_changed: "26"
  deprecated: null
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-11T00:31:51.816Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: ebfc4b4cc3bd6985763f874641ffe51d90b1cb72dbd3d4c8b31c9b08489bb519
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/CRM/Segment/SegManagement.Codeunit.al
    title: src/Layers/W1/BaseApp/CRM/Segment/SegManagement.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
object_type: codeunit
object_id: 5051
name: SegManagement
namespace: Microsoft.CRM.Segment
app: Base Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "24"
  - "25"
  - "26"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 61
  events: 42
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 0
  calls: 3
  called_by: 35
  implements: 0
---

# Codeunit 5051 "SegManagement"

> Codeunit 5051 "SegManagement" in Base Application (Microsoft.CRM.Segment). 9 public procedures, 42 events. Present since at least BC23, still in BC30, changed in BC24-26.

Base Application · Microsoft.CRM.Segment · BC23-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/CRM/Segment/SegManagement.Codeunit.al) · facts from BC29

## Properties

| Property | Value |
|---|---|
| Permissions | tabledata "Interaction Log Entry" = rimd, tabledata "Interaction Template" = r, tabledata "Inter. Log Entry Comment Line" = rd, tabledata Contact = r |

## Events published

- `OnAfterFindInteractTemplateCode(DocumentType: Enum "Interaction Log Entry Document Type"; InteractionTemplateSetup: Record "Interaction Template Setup"; var InteractionTemplateCode: Code[10])` (integration)
- `OnAfterFindInteractTmplSetupCaption(DocumentType: Integer; InteractionTemplateSetup: Record "Interaction Template Setup"; var InteractionTemplateCaption: Text[80])` (integration)
- `OnAfterInsertFollowUpSegment(var SegmentHeader: Record "Segment Header"; LoggedSegment: Record "Logged Segment")` (integration)
- `OnAfterHandleAttachmentFile(var SegmentLine: Record "Segment Line"; Attachment: Record Attachment; FileExported: Boolean)` (integration)
- `OnAfterLogInteraction(var SegmentLine: Record "Segment Line"; var InteractionLogEntry: Record "Interaction Log Entry"; Deliver: Boolean; Postponed: Boolean)` (integration)
- `OnAfterLogSegment(var TempDeliverySorter: Record "Delivery Sorter" temporary; var LoggedSegment: Record "Logged Segment"; SegmentHeader: Record "Segment Header"; SegmentNo: Code[20]; LastInteractLogEntryNo: Integer)` (integration)
- `OnBeforeAttachmentInsert(SegmentLine: Record "Segment Line"; var AttachmentTemp: Record Attachment; var Attachment: Record Attachment)` (integration)
- `OnBeforeAssignCorrespondenceTypeForEmail(var SegmentLine: Record "Segment Line"; Contact: Record Contact; ContactAltAddr: Record "Contact Alt. Address"; var IsHandled: Boolean)` (integration)
- `OnBeforeCampaignEntryNoModify(var SegmentLine: Record "Segment Line")` (integration)
- `OnBeforeCheckSalesperson(var SegmentLine: Record "Segment Line"; var IsHandled: Boolean)` (integration)
- `OnBeforeDeliverySorterInsert(var TempDeliverySorter: Record "Delivery Sorter" temporary; SegmentLine: Record "Segment Line")` (integration)
- `OnBeforeInteractLogEntryInsert(var InteractionLogEntry: Record "Interaction Log Entry"; SegmentLine: Record "Segment Line")` (integration)
- `OnBeforeLogInteraction(var SegmentLine: Record "Segment Line"; var Attachment: Record Attachment; var InterLogEntryCommentLine: Record "Inter. Log Entry Comment Line"; var Deliver: Boolean; var Postponed: Boolean)` (integration)
- `OnBeforeLogSegment(SegmentHeader: Record "Segment Header"; Deliver: Boolean; Followup: Boolean)` (integration)
- `OnBeforeLoggedSegmentInsert(var LoggedSegment: Record "Logged Segment")` (integration)
- `OnBeforeTempSegmentLineInsert(var TempSegmentLine: Record "Segment Line")` (integration)
- `OnBeforeTestFieldsFromLogInteraction(var SegmentLine: Record "Segment Line"; Deliver: Boolean; Postponed: Boolean; var IsHandled: Boolean)` (integration)
- `OnLogDocumentOnAfterFindInteractTmplCode(var InteractTmplCode: Code[10]; var Attachment: Record Attachment; DocumentType: Integer)` (integration)
- `OnLogDocumentOnCaseElse(AccountTableNo: Integer; AccountNo: Code[20]; var ContNo: Code[20])` (integration)
- `OnLogDocumentOnBeforeTempSegmentLineModify(var TempSegmentLine: Record "Segment Line" temporary; AccountTableNo: Integer; AccountNo: Code[20])` (integration)
- `OnLogInteractionOnBeforeInteractionLogEntryInsert(var InteractionLogEntry: Record "Interaction Log Entry"; Attachment: Record Attachment; SegmentLine: Record "Segment Line")` (integration)
- `OnLogInteractionOnBeforeInteractionLogEntryModify(var InteractionLogEntry: Record "Interaction Log Entry")` (integration)
- `OnLogInteractionOnAfterGetInteractLogEntryFromSegmentLine(var InteractionLogEntry: Record "Interaction Log Entry"; SegmentLine: Record "Segment Line"; Postponed: Boolean)` (integration)
- `OnLogInteractionOnBeforeInterLogEntryCommentLineInsert(var InterLogEntryCommentLine: Record "Inter. Log Entry Comment Line")` (integration)
- `OnLogInteractionOnBeforeTempDeliverySorterInsert(var DeliverySorter: Record "Delivery Sorter"; SegmentLine: Record "Segment Line"; InteractionLogEntry: Record "Interaction Log Entry")` (integration)
- `OnLogSegmentOnAfterCreateInteractionLogEntries(var SegmentHeader: Record "Segment Header"; var LoggedSegment: Record "Logged Segment")` (integration)
- `OnLogSegmentOnAfterCalcShowIsNotEmptyError(var LoggedSegment: Record "Logged Segment"; Deliver: Boolean; var ShowIsNotEmptyError: Boolean)` (integration)
- `OnLogSegmentOnAfterCalcShouldModifyAttachment(var Attachment: Record Attachment; SegmentLine: Record "Segment Line"; SegmentHeader: Record "Segment Header"; var ShouldModifyAttachment: Boolean)` (integration)
- `OnTestFieldsOnSegmentLineCorrespondenceTypeCaseElse(var SegmentLine: Record "Segment Line"; Contact: Record Contact)` (integration)
- `OnLogSegmentOnAfterLoggedSegmentInsert(var LoggedSegment: Record "Logged Segment"; SegmentHeader: Record "Segment Header")` (integration)
- `OnLogSegmentOnAfterInteractLogEntryInsert(var InteractionLogEntry: Record "Interaction Log Entry"; SegmentLine: Record "Segment Line")` (integration)
- `OnLogSegmentOnBeforeFollowupSegmentHeaderInsert(var SegmentHeader: Record "Segment Header"; LoggedSegment: Record "Logged Segment")` (integration)
- `OnLogDocumentOnBeforeTempSegmentLineInit(AccountTableNo: Integer; AccountNo: Code[20]; var ContNo: Code[20]; var Result: Integer; var IsHandled: Boolean)` (integration)
- `OnLogInteractionOnBeforeCheckAttachmentFileValue(SegmentLine: Record "Segment Line"; var AttachmentTemp: Record Attachment; var TempInterLogEntryCommentLine: Record "Inter. Log Entry Comment Line"; Deliver: Boolean; Postponed: Boolean; var NextInteractLogEntryNo: Integer; var IsHandled: Boolean)` (integration)
- `OnLogSegmentOnBeforeInitLoggedSegment(SegmentHeader: Record "Segment Header"; Deliver: Boolean; Followup: Boolean; var IsHandled: Boolean)` (integration)
- `OnBeforeCheckSegmentLine(var SegmentLine: Record "Segment Line"; Deliver: Boolean; var IsHandled: Boolean)` (integration)
- `OnLogDocumentOnBeforeTestTmplLanguage(InteractTmplCode: Code[10]; var IsHandled: Boolean)` (integration)
- `OnAfterCopyFieldsToCampaignEntry(var CampaignEntry: Record "Campaign Entry"; var SegmentLine: Record "Segment Line")` (integration)
- `OnLogInteractionOnAfterInterLogEntryCommentLineInsert(var InterLogEntryCommentLine: Record "Inter. Log Entry Comment Line"; SegmentLine: Record "Segment Line"; NextInteractLogEntryNo: Integer)` (integration)
- `OnLogInteractionOnBeforeInteractLogEntryGet(var NextInteractLogEntryNo: Integer; SegmentLine: Record "Segment Line"; Postponed: Boolean; var IsHandled: Boolean)` (integration)
- `OnLogInteractionOnBeforeWizSaveAttachment(SegmentLine: Record "Segment Line"; var AttachmentTemp: Record Attachment; var Attachment: Record Attachment)` (integration)
- `OnBeforeExportAttachmentFile(var SegmentLine: Record "Segment Line"; Attachment: Record Attachment; var AttachmentTemp: Record Attachment; var FileExported: Boolean; var IsHandled: Boolean)` (integration)

## Procedures

- `LogSegment(SegmentHeader: Record "Segment Header"; Deliver: Boolean; Followup: Boolean)`
- `LogInteraction(SegmentLine: Record "Segment Line"; var AttachmentTemp: Record Attachment; var TempInterLogEntryCommentLine: Record "Inter. Log Entry Comment Line"; Deliver: Boolean; Postponed: Boolean): Integer`
- `LogDocument(DocumentType: Integer; DocumentNo: Code[20]; DocNoOccurrence: Integer; VersionNo: Integer; AccountTableNo: Integer; AccountNo: Code[20]; SalespersonCode: Code[20]; CampaignNo: Code[20]; Description: Text[100]; OpportunityNo: Code[20]): Integer`
- `UnwrapAttachmentCustomLayout(var SegmentLine: Record "Segment Line")` (internal)
- `FindInteractionTemplateCode(DocumentType: Enum "Interaction Log Entry Document Type"): Code[10]`
- `CheckSegmentLine(var SegmentLine: Record "Segment Line"; Deliver: Boolean)`
- `CopyFieldsToCampaignEntry(var CampaignEntry: Record "Campaign Entry"; var SegmentLine: Record "Segment Line")`
- `CreateCampaignEntryOnSalesInvoicePosting(SalesInvoiceHeader: Record "Sales Invoice Header")`
- `InterLogEntryCommentLineInsert(var TempInterLogEntryCommentLine: Record "Inter. Log Entry Comment Line"; InteractionLogEntryNo: Integer)`

Plus 10 local procedures.

## Triggers

OnRun

## Calls

From the extracted call graph of BC29 (graphify-al on the snapshot checkout): calls whose target is known from a declared type or an `Object::"Name"` argument. Interface dispatch and calls through events are not counted, so the list is not complete.

- [Codeunit 5052 "AttachmentManagement"](../codeunit/5052.md) (3 calls: `LogInteraction → Send`, `LogSegment → Send`, `UnwrapAttachmentCustomLayout → GenerateHTMLContent`)
- [Codeunit 9500 "Sequence No. Mgt."](../codeunit/9500.md) (2 calls: `LogInteraction → GetNextSeqNo`, `LogSegment → GetNextSeqNo`)
- [Codeunit 419 "File Management"](../codeunit/419.md) (1 call: `ExportAttachmentFile → DeleteServerFile`)

## Called by

- [Codeunit 5679 "Create Interaction Log Entry"](../codeunit/5679.md) (4 calls: `CreateInteractionLogEntryForContact → LogDocument`, `CreateInteractionLogEntryForCustomer → LogDocument`, `CreateInteractionLogEntryForPurchaseHeader → LogDocument`, …)
- [Table 5077 "Segment Line"](../table/5077.md) (4 calls: `CreateSegLineInteractionFromContactForEmail → LogInteraction`, `FinishSegLineWizard → LogInteraction`, `LogSegLinePhoneCall → LogInteraction`, …)
- [Report 118 "Finance Charge Memo"](../report/118.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 1303 "Standard Sales - Draft Invoice"](../report/1303.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 1304 "Standard Sales - Quote"](../report/1304.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 1305 "Standard Sales - Order Conf."](../report/1305.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 1306 "Standard Sales - Invoice"](../report/1306.md) (2 calls: `LogInteractionTemplateExists → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 1307 "Standard Sales - Credit Memo"](../report/1307.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 1308 "Standard Sales - Shipment"](../report/1308.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 1309 "Standard Sales - Return Rcpt."](../report/1309.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 1316 "Standard Statement"](../report/1316.md) (2 calls: `InitInteractionLog → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 1322 "Standard Purchase - Order"](../report/1322.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 208 "Sales - Shipment"](../report/208.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 210 "Blanket Sales Order"](../report/210.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 404 "Purchase - Quote"](../report/404.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 405 "Order"](../report/405.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 406 "Purchase - Invoice"](../report/406.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 407 "Purchase - Credit Memo"](../report/407.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 408 "Purchase - Receipt"](../report/408.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 410 "Blanket Purchase Order"](../report/410.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 413 "Self Billing Invoice"](../report/413.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 6222 "EUDR Sales Invoice"](../report/6222.md) (2 calls: `LogInteractionTemplateExists → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 6631 "Return Order Confirmation"](../report/6631.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 6636 "Purchase - Return Shipment"](../report/6636.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 6641 "Return Order"](../report/6641.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Report 6646 "Sales - Return Receipt"](../report/6646.md) (2 calls: `InitLogInteraction → FindInteractionTemplateCode`, `OnPostReport → LogDocument`)
- [Codeunit 80 "Sales-Post"](../codeunit/80.md) (1 call: `InsertInvoiceHeader → CreateCampaignEntryOnSalesInvoicePosting`)
- [Report 116 "Statement"](../report/116.md) (1 call: `OnPostReport → LogDocument`)
- [Report 117 "Reminder"](../report/117.md) (1 call: `OnPostReport → LogDocument`)
- [Report 5055 "Contact - Cover Sheet"](../report/5055.md) (1 call: `OnPostReport → LogDocument`)
- [Report 5902 "Service Quote"](../report/5902.md) (1 call: `OnPostReport → LogDocument`)
- [Report 5970 "Service Contract"](../report/5970.md) (1 call: `OnPostReport → LogDocument`)
- [Report 5972 "Service Contract Quote"](../report/5972.md) (1 call: `OnPostReport → LogDocument`)
- [Table 5080 "To-do"](../table/5080.md) (1 call: `LogTaskInteraction → LogInteraction`)
- [Table 5901 "Service Item Line"](../table/5901.md) (1 call: `OnInsert → LogDocument`)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC24-26

Source: AL metadata extracted from the code (names, ids, signatures, properties); no code bodies (D10).

## Ask your agent

Procedure bodies are not stored here (D10). The call sections above are our own, per object, from the BC29 call graph. For a procedure body or the calls of one procedure, ask bc-code-atlas (external, by Stefan Maron, MIT; default corpus w1-28), which the bc-observatory plugin connects: `bcatlas_resolve_node(object_type: "codeunit", object_name: "SegManagement")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
