---
sourceDocument: Australia API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/de-DE/api-reference

 Release :

    - australia

ft:locale :

    - de-DE

ft:publication_title :

    - Australia API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# SegmentHandler API - Scoped

# SegmentHandler API - Scoped {#ariaid-title1}

* Freigeben Version: Australia
* 
* Aktualisiert 12. März 2026
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 Minuten Lesedauer

Script include providing a chainable API for building an IDoc payload for a specific operation.

This script include requires the Zero Copy Connector for ERP (com.sn_erp_integration) store application and is provided within the sn_erp_integration namespace. For more information, refer to [Zero Copy Connector for ERP](https://www.servicenow.com/docs/access?context=erp-integration-overview&version=australia&pubname=australia-integrate-applications&ft:locale=en-US).

Role required: sn_erp_integration.erp_user

sn_erp_integration namespace  
* Owns the root data object and the IDoc segment schema.
* Creates **top-level segments** (e.g. `E1EDK01`, `E1EDP01`).

{#SegmentHandlerAPIScoped__ul_ex3_hjk_c3c}For handling lower-level instances of a segment, such as a header or item, refer to [SegmentHandle API - Scoped](https://servicenow-prod.fluidtopics.net/t3BD5bfegZMvtoIw28nSmg#SegmentHandleAPIScoped "Methods provided by the SegmentHandler script include for handling a single instance of a segment, such as a header or item.").

See also: [sn_erp_integration API - Scoped, Global](https://servicenow-prod.fluidtopics.net/Ak37pOBjI0LlCWVkdZlViA#sn_erp_integrationBothAPI "Script include providing a chainable API for interacting with Zero Copy Connector for ERP (Enterprise Resource Planning) models.").

## SegmentHandler - SegmentHandler(String operationId) {#ariaid-title2}

Instantiates a new SegmentHandler object bound to an IDoc operation.
{#SegmentHandler-SegmentHandler_O__table_qlv_2gw_3hc__entry__3}

| Name | Type | Description |
|-|-|-|
| operationId | String | The sys_id of a configured ERP model operation. Table: ERP model operation \[sn_erp_integration_model_operation\] |
[Tabelle : 1. Parameters]

{#SegmentHandler-SegmentHandler_O__table_qlv_2gw_3hc}  
The following example shows Build a header and item with nested segments in one fluent chain. The structure depends on the configured schema, but the pattern---arrays of segments with nested arrays---is the same.

    let obj = new sn_erp_integration.SegmentHandler('460d3ff2ff5de210d3a2fffffffffff8');

    obj.addSegment("E1EDK01")
        .addField("BELNR", "1000")
        .addField("CURCY", "USD")
        .endSegment()
        .addSegment("E1EDP01")
        .addField("MENGE", "50")
        .addField("POSEX", "0010")
        .addSegment("E1EDP20")
        .addField("AMENG", "10")
        .addField("WMENG", "5")
        .addSegment("E1EDP19")
        .addField("IDTNR", "MAT01")
        .endSegment()
        .endSegment()
        .endSegment();

    gs.info(JSON.stringify(obj.getData(), null, 2));

Output:

    {
      "data": {
        "E1EDK01": [{
          "BELNR": "1000",
          "CURCY": "USD"
        }],
          "E1EDP01": [{
            "MENGE": "50",
            "POSEX": "0010",
            "E1EDP20": [{
              "AMENG": "10",
              "WMENG": "5",
              "E1EDP19": [{
                "IDTNR": "MAT01"
              }]
            }]
          }]
      }
    }

## SegmentHandler - addSegment(String segmentName, Object values) {#ariaid-title3}

Adds a predefined top-level segment of type segmentName to the payload.
Hinweis:  
The segment must be defined in the operation.
{#SegmentHandler-addSegment_S_O__table_qkt_53x_3hc__entry__3}

| Name | Type | Description |
|-|-|-|
| segmentName | String | Name of the top-level segment. |
| values | Object | Optional implementation in place of the addField() method. |
[Tabelle : 2. Parameters]

{#SegmentHandler-addSegment_S_O__table_qkt_53x_3hc} {#SegmentHandler-addSegment_S_O__table_rkt_53x_3hc__entry__2}

| Type | Description |
|-|-|
| Object | [SegmentHandle](https://servicenow-prod.fluidtopics.net/t3BD5bfegZMvtoIw28nSmg#SegmentHandleAPIScoped "Methods provided by the SegmentHandler script include for handling a single instance of a segment, such as a header or item.") for the new segment instance. |
[Tabelle : 3. Returns]

{#SegmentHandler-addSegment_S_O__table_rkt_53x_3hc}  
The following example shows Build a header and item with nested segments in one fluent chain. The structure depends on the configured schema, but the pattern---arrays of segments with nested arrays---is the same.

    let obj = new sn_erp_integration.SegmentHandler('460d3ff2ff5de210d3a2fffffffffff8');

    obj.addSegment("E1EDK01")
        .addField("BELNR", "1000")
        .addField("CURCY", "USD")
        .endSegment()
        .addSegment("E1EDP01")
        .addField("MENGE", "50")
        .addField("POSEX", "0010")
        .addSegment("E1EDP20")
        .addField("AMENG", "10")
        .addField("WMENG", "5")
        .addSegment("E1EDP19")
        .addField("IDTNR", "MAT01")
        .endSegment()
        .endSegment()
        .endSegment();

    gs.info(JSON.stringify(obj.getData(), null, 2));

Output:

    {
      "data": {
        "E1EDK01": [{
          "BELNR": "1000",
          "CURCY": "USD"
        }],
          "E1EDP01": [{
            "MENGE": "50",
            "POSEX": "0010",
            "E1EDP20": [{
              "AMENG": "10",
              "WMENG": "5",
              "E1EDP19": [{
                "IDTNR": "MAT01"
              }]
            }]
          }]
      }
    }

## SegmentHandler - getData() {#ariaid-title4}

Gets the built segment payload.
{#SegmentHandler-getData__table_qkt_53x_3hc__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 4. Parameters]

{#SegmentHandler-getData__table_qkt_53x_3hc} {#SegmentHandler-getData__table_rkt_53x_3hc__entry__2}

| Type | Description |
|-|-|
| Object | The payload object containing all top-level and nested segments. Exact structure depends on the configured schema, but the pattern---arrays of segments with nested arrays---is the same. |
[Tabelle : 5. Returns]

{#SegmentHandler-getData__table_rkt_53x_3hc}  
The following example shows Build a header and item with nested segments in one fluent chain. The structure depends on the configured schema, but the pattern---arrays of segments with nested arrays---is the same.

    let obj = new sn_erp_integration.SegmentHandler('460d3ff2ff5de210d3a2fffffffffff8');

    obj.addSegment("E1EDK01")
        .addField("BELNR", "1000")
        .addField("CURCY", "USD")
        .endSegment()
        .addSegment("E1EDP01")
        .addField("MENGE", "50")
        .addField("POSEX", "0010")
        .addSegment("E1EDP20")
        .addField("AMENG", "10")
        .addField("WMENG", "5")
        .addSegment("E1EDP19")
        .addField("IDTNR", "MAT01")
        .endSegment()
        .endSegment()
        .endSegment();

    gs.info(JSON.stringify(obj.getData(), null, 2));

Output:

    {
      "data": {
        "E1EDK01": [{
          "BELNR": "1000",
          "CURCY": "USD"
        }],
          "E1EDP01": [{
            "MENGE": "50",
            "POSEX": "0010",
            "E1EDP20": [{
              "AMENG": "10",
              "WMENG": "5",
              "E1EDP19": [{
                "IDTNR": "MAT01"
              }]
            }]
          }]
      }
    }


