# Generate Dynamic Lines in EDI File

**URL:** <https://forum.alumio.com/t/generate-dynamic-lines-in-edi-file/616>\
**Category:** General\
**Tags:** edi\
**Created:** [May 29, 2023, 10:34am UTC](https://forum.alumio.com/t/generate-dynamic-lines-in-edi-file/616 "2023-05-29T10:34:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fahadmicro](https://forum.alumio.com/letter_avatar_proxy/v4/letter/f/7cd45c/32.png) [@fahadmicro](https://forum.alumio.com/u/fahadmicro)\
**Post date:** [May 29, 2023, 10:34am UTC](https://forum.alumio.com/t/generate-dynamic-lines-in-edi-file/616/1 "2023-05-29T10:34:58Z")

</div>

Hello @Gugi @Alumio_Bot @Ruben I receive incoming Shopify order data in JSON format. Using an Entity Transformer, I convert this data into an EDI format. The Entity Transformer utilizes a Value Setter that uses object type to set value. The values for the EDI format are extracted from the JSON input using the syntax ‘&{}’. This process allows me to transform the Shopify order data into a standardized EDI format for further processing.  
Now, in Shopify Orders, there are line\_items that are dynamic. In EDI, there is a PO1 loop for adding Product quantities and their titles  
 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/1X/ed370e930d07b37290bd30170f235d2fd78ff2b6.png)

Based on the provided image, the pattern “PO1_1" represents items[0], "PO1_ 2” represents items[1], and so on. These lines can repeat dynamically as “PO1_3" and beyond. Additionally, the "PID_ F” line is part of the PO1 loop, and its presence in the EDI format will also be dynamic. How can I achieve this in Alumio Entity Transformer?

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/1X/d0f5c2f1493f219b140b5c3d59467ff18fff042d.png)

The output Results:

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/1X/92a9b6abba1b0ca5dbdb44409d46ef109dcacdb0.png)

---

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [May 29, 2023, 1:05pm UTC](https://forum.alumio.com/t/generate-dynamic-lines-in-edi-file/616/2 "2023-05-29T13:05:41Z")

</div>

Hi @fahadmicro

Could you please let me know whether you have tried the entity transformer called [Alumio - EDI - Serialize](https://forum.alumio.com/t/alumio-edi-serialize-transformer/585) to map a JSON format into EDI? Or, do you want to transform your data manually into EDI using the transformer prototypes?

---

<div class="post-metadata">

**Author:** ![fahadmicro](https://forum.alumio.com/letter_avatar_proxy/v4/letter/f/7cd45c/32.png) [@fahadmicro](https://forum.alumio.com/u/fahadmicro)\
**Post date:** [May 29, 2023, 1:24pm UTC](https://forum.alumio.com/t/generate-dynamic-lines-in-edi-file/616/3 "2023-05-29T13:24:19Z")

</div>

@Gugi Yes, I have tried to Convert the whole JSON to EDI using the entity transformer called [Alumio - EDI - Serialize](https://forum.alumio.com/t/alumio-edi-serialize-transformer/585) to map a JSON format into EDI but I got “Bad Request” Error

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/1X/93172cd996acd782658dcc03d7801cd8b353738a.png)

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/1X/e7943df9bf477b15dc411daa45353d8307d4953b.png)

Therefore, I am manually generating the EDI from JSON format.

---

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [May 29, 2023, 2:23pm UTC](https://forum.alumio.com/t/generate-dynamic-lines-in-edi-file/616/4 "2023-05-29T14:23:58Z")

</div>

@fahadmicro Before using the Alumio - EDI - Serialize, you should transform your order into a JSON format defined in the below file.

[json-formatted-x12.json](https://forum.alumio.com/uploads/short-url/m1MYFXMevO3xnJAqO7VptQkISLx.json) (20.3 KB)

The line items should be mapped into the array `Groups.0.Transactions.0.PO1Loop`. Additionally, please leave the `postfix` parameter in the Request Parameters field as an empty string.

The above JSON format will be converted into the below output in X12-standard EDI.

```auto
ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>
GS*PO*4405197800*999999999*20101127*1719*1421*X*004010VICS
ST*850*000000010
BEG*00*SA*08292233294**20101127*610385385
REF*DP*038
REF*PS*R
ITD*14*3*2 **45** 46
DTM*002*20101214
PKG*F*68***PALLETIZE SHIPMENT
PKG*F*66***REGULAR
TD5*A*92*P3**SEE XYZ RETAIL ROUTING GUIDE
N1*ST*XYZ RETAIL*9*0003947268292
N3*31875 SOLON RD
N4*SOLON*OH*44139
PO1*1*120*EA*9.25*TE*CB*065322-117*PR*RO*VN*AB3542
PID*F **** SMALL WIDGET
PO4*4*4*EA*PLT94**3*LR*15*CT
PO1*2*220*EA*13.79*TE*CB*066850-116*PR*RO*VN*RD5322
PID*F **** MEDIUM WIDGET
PO4*2*2*EA
PO1*3*126*EA*10.99*TE*CB*060733-110*PR*RO*VN*XY5266
PID*F **** LARGE WIDGET
PO4*6*1*EA*PLT94**3*LR*12*CT
CTT*3
AMT*1*13045.94
SE*24*000000010
GE*1*1421
IEA*1*000003438

```

Please give it a try and let us know if you have any questions.

---

<div class="post-metadata">

**Author:** ![fahadmicro](https://forum.alumio.com/letter_avatar_proxy/v4/letter/f/7cd45c/32.png) [@fahadmicro](https://forum.alumio.com/u/fahadmicro)\
**Post date:** [May 30, 2023, 1:25pm UTC](https://forum.alumio.com/t/generate-dynamic-lines-in-edi-file/616/5 "2023-05-30T13:25:05Z")

</div>

@Gugi Thanks. I have created the required JSON format and now I am able to use Alumio - EDI - Serialize. Now, I have only one query about how I can handle the PO1 loop i.e. from line\_items. I need to know how I can dynamically create an array of objects and use them with my parent data.

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/1X/5251e2292cfdf3a98a44ab19dbcc2d8635736d70.png)  
As there is also an assigned number which increments with each object i.e. PO1_1, PO1_2…  
Therefore, how will I transform this?

---

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [May 30, 2023, 1:58pm UTC](https://forum.alumio.com/t/generate-dynamic-lines-in-edi-file/616/6 "2023-05-30T13:58:38Z")

</div>

@fahadmicro You can use the [Node, transform nodes](https://forum.alumio.com/t/node-transformer/348) entity transformer to loop through the `line_items` in your Shopify order entity. Inside the node transformer, you can then transform each line item to match the `Groups.0.Transactions.0.PO1Loop` format.

However, in order to get the index of each line item, before entering the above Node transformer, you should put use the [Move data between accessors](https://forum.alumio.com/t/move-data-between-accessors/284) to map the index of `line_items` array into an accessible property inside the each `line_items` object. See the below picture.

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/1X/792d21639758035ccb5ec64e4d899af84719279f.png)

The above transformer will result in the below `PO1loop` array.

```auto
{
  "PO1loop": [
    {
      "index": "0", // the index
      "line_item": {
        ...
        "id": 669751112,
        "price": "199.99",
        "product_id": 7513594,
        "quantity": 1,
        "requires_shipping": true,
        "sku": "IPOD-342-N",
        "title": "IPod Nano",
        "variant_id": 4264112,
        "variant_title": "Pink",
        ...
      }
    },
    {
      "index": "1", // the index
      "line_item": {
        ...
        "id": 669751113,
        "price": "199.99",
        "product_id": 7513594,
        "quantity": 1,
        "requires_shipping": true,
        "sku": "IPOD-342-N",
        "title": "IPod Nano",
        "variant_id": 4264112,
        "variant_title": "Pink",
        ...
      }
    }
  ]
}

```

You can use the Node transformer to loop through the `PO1loop` array instead of looping through the original `line_items` array.

---

<div class="post-metadata">

**Author:** ![fahadmicro](https://forum.alumio.com/letter_avatar_proxy/v4/letter/f/7cd45c/32.png) [@fahadmicro](https://forum.alumio.com/u/fahadmicro)\
**Post date:** [May 31, 2023, 1:10pm UTC](https://forum.alumio.com/t/generate-dynamic-lines-in-edi-file/616/7 "2023-05-31T13:10:28Z")

</div>

@Gugi Thank You. It worked perfectly.
