---
id: object/codeunit/1302
type: object
title: Codeunit 1302 "Customer Mgt."
summary: Codeunit 1302 "Customer Mgt." in Base Application (Microsoft.Sales.Customer). 25 public procedures, 7 events. Present since at least BC23, still in BC30, changed in BC24-25, BC27.
tier: official
language: en
tags:
  - codeunit
  - base application
versions:
  introduced: null
  last_changed: "27"
  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: fa943ca97308819efe02b1172f63f1ea7b59225c6f51e525949b447ce594ada3
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Sales/Customer/CustomerMgt.Codeunit.al
    title: src/Layers/W1/BaseApp/Sales/Customer/CustomerMgt.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: 1302
name: Customer Mgt.
namespace: Microsoft.Sales.Customer
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"
  - "27"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 37
  events: 7
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 0
  calls: 10
  called_by: 9
  implements: 0
---

# Codeunit 1302 "Customer Mgt."

> Codeunit 1302 "Customer Mgt." in Base Application (Microsoft.Sales.Customer). 25 public procedures, 7 events. Present since at least BC23, still in BC30, changed in BC24-25, BC27.

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

## Events published

- `OnAfterSetFilterForPostedDocs(var CustLedgEntry: Record "Cust. Ledger Entry")` (integration): Raised after setting filters for posted customer ledger entries.
- `OnAfterSetFilterForUnpostedLines(var SalesLine: Record "Sales Line")` (integration): Raised after setting filters for unposted sales lines.
- `OnBeforeGetTotalSales(CustNo: Code[20]; var Result: Decimal; var IsHandled: Boolean)` (integration): Raised before calculating the total sales for a customer.
- `SkipSettingFilter(var SkipSetFilter: Boolean)` (integration): Raised to allow skipping the date filter setting for current year calculations.
- `OnAfterCalculateShipBillToOptions(var ShipToOptions: Enum "Sales Ship-to Options"; var BillToOptions: Enum "Sales Bill-to Options"; SalesHeader: Record "Sales Header")` (integration): Raised after calculating the ship-to and bill-to options for a sales header.
- `OnBeforeSearchForExternalDocNo(var OriginalSalesHeader: Record "Sales Header"; var ResultFound: Boolean; var IsHandled: Boolean)` (integration): Raised before searching for duplicate external document numbers.
- `OnBeforeCalculateStatisticsWithCurrentCustomerValues(var Customer: Record Customer; var AdjmtCostLCY: Decimal; var AdjCustProfit: Decimal; var AdjProfitPct: Decimal; var CustInvDiscAmountLCY: Decimal; var CustPaymentsLCY: Decimal; var CustSalesLCY: Decimal; var CustProfit: Decimal; var IsHandled: Boolean)` (integration): Raised before calculating customer statistics using current customer field values.

## Procedures

- `CalculatePaymentStats(CustomerNo: Code[20]; var Stats: Dictionary of [Text, Text])`: Calculates payment statistics for a customer including average days to pay, late payment counts, and overdue invoices.
- `CalcLastPaymentInfo(CustomerNo: Code[20]; var Stats: Dictionary of [Text, Text])`: Retrieves the last payment information for a customer including date, amount, and whether it was paid on time.
- `CalcNumberOfDistinctItemsSold(CustomerNo: Code[20]; var Stats: Dictionary of [Text, Text])`: Calculates the number of distinct items that have been sold to a customer.
- `CalculateInteractionStats(CustomerNo: Code[20]; var Stats: Dictionary of [Text, Text])`: Calculates interaction statistics for a customer including total count, last interaction date, and most frequent type.
- `CalculateStatistic(Customer: Record Customer; var AdjmtCostLCY: Decimal; var AdjCustProfit: Decimal; var AdjProfitPct: Decimal; var CustInvDiscAmountLCY: Decimal; var CustPaymentsLCY: Decimal; var CustSalesLCY: Decimal; var CustProfit: Decimal)`: Calculates customer statistics including sales, profit, and cost adjustments for the current fiscal year.
- `CalculateStatisticsWithCurrentCustomerValues(var Customer: Record Customer; var AdjmtCostLCY: Decimal; var AdjCustProfit: Decimal; var AdjProfitPct: Decimal; var CustInvDiscAmountLCY: Decimal; var CustPaymentsLCY: Decimal; var CustSalesLCY: Decimal; var CustProfit: Decimal)`: Calculates customer statistics using current customer field values without applying date filters.
- `CalcAmountsOnPostedInvoices(CustNo: Code[20]; var RecCount: Integer): Decimal`: Calculates the total sales amount on posted invoices for a customer within the current year.
- `CalcAmountsOnPostedCrMemos(CustNo: Code[20]; var RecCount: Integer): Decimal`: Calculates the total sales amount on posted credit memos for a customer within the current year.
- `CalcAmountsOnOrders(CustNo: Code[20]; var RecCount: Integer): Decimal`: Calculates the total outstanding amount on sales orders for a customer.
- `CalcAmountsOnQuotes(CustNo: Code[20]; var RecCount: Integer): Decimal`: Calculates the total outstanding amount on sales quotes for a customer.
- `CalculateAmountsWithVATOnUnpostedDocuments(CustNo: Code[20]): Decimal`: Calculates the total outstanding amount including VAT on unposted invoices and credit memos for a customer.
- `CalculateAmountsOnUnpostedInvoices(CustNo: Code[20]; var RecCount: Integer): Decimal`: Calculates the total outstanding amount on unposted sales invoices for a customer.
- `CalculateAmountsOnUnpostedCrMemos(CustNo: Code[20]; var RecCount: Integer): Decimal`: Calculates the total outstanding amount on unposted sales credit memos for a customer.
- `DrillDownOnPostedInvoices(CustNo: Code[20])`: Opens the Posted Sales Invoices page filtered for the specified customer within the current year.
- `DrillDownOnPostedCrMemo(CustNo: Code[20])`: Opens the Posted Sales Credit Memos page filtered for the specified customer within the current year.
- `DrillDownOnOrders(CustNo: Code[20])`: Opens the Sales Order List page filtered for the specified customer.
- `DrillDownOnQuotes(CustNo: Code[20])`: Opens the Sales Quotes page filtered for the specified customer.
- `DrillDownMoneyOwedExpected(CustNo: Code[20])`: Opens the Sales List page showing unposted invoices and credit memos for the specified customer.
- `DrillDownOnUnpostedInvoices(CustNo: Code[20])`: Opens the Sales Invoice List page filtered for unposted invoices of the specified customer.
- `DrillDownOnUnpostedCrMemos(CustNo: Code[20])`: Opens the Sales Credit Memos page filtered for unposted credit memos of the specified customer.
- `GetCurrentYearFilter(): Text[30]`: Retrieves the date filter for the current fiscal year or accounting period.
- `GetTotalSales(CustNo: Code[20]): Decimal`: Calculates the total sales for a customer including posted and outstanding invoices and credit memos.
- `GetYTDSales(CustNo: Code[20]): Decimal`: Calculates the year-to-date sales for a customer using fiscal year totals.
- `SearchForExternalDocNo(var OriginalSalesHeader: Record "Sales Header"): Boolean`: Searches for duplicate external document numbers in sales documents and posted documents.
- `CalculateShipBillToOptions(var ShipToOptions: Enum "Sales Ship-to Options"; var BillToOptions: Enum "Sales Bill-to Options"; var SalesHeader: Record "Sales Header")`: Calculates the ship-to and bill-to options based on the sales header address information.

Plus 5 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 32 "Customer Card Calculations"](../codeunit/32.md) (14 calls: `CalcLastPaymentInfo → GetLastPaymentAmountLabel`, `CalcLastPaymentInfo → GetLastPaymentDateLabel`, `CalcLastPaymentInfo → GetLastPaymentOnTimeLabel`, …)
- [Codeunit 358 "DateFilter-Calc"](../codeunit/358.md) (2 calls: `GetCurrentYearFilter → CreateAccountingPeriodFilter`, `GetCurrentYearFilter → CreateFiscalYearFilter`)
- [Codeunit 5836 "Cost Calculation Management"](../codeunit/5836.md) (2 calls: `CalculateStatisticsWithCurrentCustomerValues → CalcCustActualCostLCY`, `CalculateStatisticsWithCurrentCustomerValues → NonInvtblCostAmt`)
- [Page 45 "Sales List"](../page/45.md) (1 call: `DrillDownMoneyOwedExpected → (object)`)
- [Page 9300 "Sales Quotes"](../page/9300.md) (1 call: `DrillDownOnQuotes → (object)`)
- [Page 9301 "Sales Invoice List"](../page/9301.md) (1 call: `DrillDownOnUnpostedInvoices → (object)`)
- [Page 9302 "Sales Credit Memos"](../page/9302.md) (1 call: `DrillDownOnUnpostedCrMemos → (object)`)
- [Page 9305 "Sales Order List"](../page/9305.md) (1 call: `DrillDownOnOrders → (object)`)
- [Query 2460 "Posted Sales Invoices"](../query/2460.md) (1 call: `DrillDownOnPostedInvoices → (object)`)
- [Query 2461 "Posted Sales Credit Memos"](../query/2461.md) (1 call: `DrillDownOnPostedCrMemo → (object)`)

## Called by

- [Codeunit 32 "Customer Card Calculations"](../codeunit/32.md) (9 calls: `OnRun → CalcAmountsOnPostedCrMemos`, `OnRun → CalcAmountsOnPostedInvoices`, `OnRun → CalcNumberOfDistinctItemsSold`, …)
- [Page 21 "Customer Card"](../page/21.md) (3 calls: `OnAfterGetCurrRecordFuncOData → CalculateStatistic`, `OpenCurrFiscalYearCustLedgerEntries → GetCurrentYearFilter`, `OpenCurrFiscalYearDetailedCustLedgerEntries → GetCurrentYearFilter`)
- [Page 1611 "Office Customer Details"](../page/1611.md) (2 calls: `GetTotalSales → GetTotalSales`, `GetYTDSales → GetYTDSales`)
- [Codeunit 9082 "Calculate Customer Stats."](../codeunit/9082.md) (1 call: `CalcLastPaymentDate → CalcLastPaymentInfo`)
- [Page 41 "Sales Quote"](../page/41.md) (1 call: `UpdateShipToBillToGroupVisibility → CalculateShipBillToOptions`)
- [Page 42 "Sales Order"](../page/42.md) (1 call: `UpdateShipToBillToGroupVisibility → CalculateShipBillToOptions`)
- [Page 43 "Sales Invoice"](../page/43.md) (1 call: `UpdateShipToBillToGroupVisibility → CalculateShipBillToOptions`)
- [Page 507 "Blanket Sales Order"](../page/507.md) (1 call: `UpdateShipToBillToGroupVisibility → CalculateShipBillToOptions`)
- [Table 36 "Sales Header"](../table/36.md) (1 call: `FindDocumentWithSameExternalDocNo → SearchForExternalDocNo`)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC24-25, BC27

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: "Customer Mgt.")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
