Get available to promise (ATP) quantity
This example demonstrates how to use a Calculated Attribute to retrieve an Available To Promise (ATP) quantity for a product on a specific date.
Being able to compute ATP through a Calculated Attribute allows business logic, validation rules, automations, and UI fields to dynamically reflect the product’s availability without requiring custom extensions or any external code.
In this example, the calculation determines the ATP quantity as of the Required Delivery Date of a shipment order line. The same pattern, however, can be easily adapted with minimal adjustments to calculate ATP for any other date your business logic requires.
Overview
The ATP Calculated Attribute queries the Available To Promise view, finds the ATP record that is valid as of the requested date, and returns its ATP Base Value.
This example shows how it works:
- Reads the repository of the Available To Promise view for the given product.
- Filters by Product, Store, and Enterprise Company.
- Sorts the results by
FromDate, newest first. - Applies a delivery deadline (
FromDate ≤ RequiredDeliveryDate). - Returns only the first valid record using
TOP 1. - Outputs the
ATPBaseValue, representing the promised availability.
This section provides the conceptual overview. Тhe next one shows the exact implementation.
Note
The repository of the attributes is Logistics.Shipment.ShipmentOrderLines
The ORDERBY operator for FromDate in this report is supported starting from version 26.
In earlier versions of ERP.net, ORDERBY was not available, so the same behavior had to be achieved by combining a FILTER with a SORT.
10 GETOBJVALUE EXP:20 ATTRIB:ATPBaseValue
20 FIRST EXP:30
30 SELECT REPO::Logistics.Inventory.DemandManagement.AvailableToPromise EXP:40
40 TOP CONST:1 EXP: 50
50 ORDERBY ATTRIB:FromDate CONST:DESC EXP:60
60 WHERE EXP:70 EXP:80
70 AND EXP:90 EXP:120
80 AND EXP:150 EXP:180
90 EQUAL ATTRIB:ProductId EXP:100
100 GETOBJVALUE INPUT:10 EXP:110
110 GETOBJVALUE REF::ParentSalesOrderLine ATTRIB:ProductId
120 EQUAL ATTRIB:StoreId EXP:130
130 GETOBJVALUE INPUT:10 EXP:140
140 GETOBJVALUE REF::ParentSalesOrderLine ATTRIB:LineStoreId
150 EQUAL ATTRIB:EnterpriseCompanyId EXP:160
160 GETOBJVALUE INPUT:10 EXP:170
170 GETOBJVALUE REF::ShipmentOrder ATTRIB:EnterpriseCompanyId
180 LTE ATTRIB:FromDate EXP:190
190 GETOBJVALUE INPUT:10 EXP:200
200 GETOBJVALUE REF::ShipmentOrder ATTRIB:RequiredDeliveryDate
Detailed еxplanation:
- 10: Gets the
ATPBaseValueof the record returned by EXP:20. - 20: Takes the first element from the list returned by EXP:30.
- 30: Selects the
AvailableToPromiserecords from the repository. - 40: Limits the result set to 1 record from EXP:50.
- 50: Orders the records by
FromDatein descending order (most recent first). - 60: Filters the records for which both EXP:70 and EXP:80 are
True. - 70: Returns
Trueonly if both EXP:90 and EXP:120 areTrue. - 80: Returns
Trueonly if both EXP:150 and EXP:180 areTrue. - 90: Returns
Trueif theProductIdof theAvailableToPromiserecord is equal to EXP:100. - 100: Gets EXP:110 from the repository of INPUT:10 (i.e., from the current shipment order line).
- 110: Gets the
ProductIdof theParentSalesOrderLine. - 120: Returns
Trueif theStoreIdof theAvailableToPromiserecord is equal to EXP:130. - 130: Gets EXP:140 from the repository of INPUT:10.
- 140: Gets the
LineStoreIdof theParentSalesOrderLine. - 150: Returns
Trueif theEnterpriseCompanyIdof theAvailableToPromiserecord is equal to EXP:160. - 160: Gets EXP:170 from the repository of INPUT:10.
- 170: Gets the
EnterpriseCompanyIdof theShipmentOrder. - 180: Returns
Trueif theFromDateof theAvailableToPromiserecord is less than or equal to EXP:190. - 190: Gets EXP:200 from the repository of INPUT:10.
- 200: Gets the
RequiredDeliveryDateof theShipmentOrder.