Weasel !! I Didn’t Know You Could Do This - Copilot EDI Adventure
Tags: powerfuldevs, powerautomate, githubcopilot, edi
Published: 2024-06-03 07:04:28

## Intro:

In my job of designing and checking systems, I often look at the data-sharing agreements between them. Sometimes, when updating to newer systems, I need to understand how data is shared with older systems and even outside companies. A common challenge is that this data sharing is done using a business-to-business format known as EDI (Electronic Data Interchange). In EDI, the companies exchanging documents are called “trading partners.” They decide together what data will be sent and how it will be used, following guidelines that are written in a way people can understand. These guidelines are like blueprints, while the EDI standards they follow are like building codes. To make sense of a message, you need to know these standards and guidelines. As we work on modernizing, one idea is to make the way we exchange messages simpler. Analyzing these messages would require an EDI interpreter to quickly figure out how complex the data is. This led me to wonder if there’s a faster way to interpret these messages, which would help with planning and estimating the work needed before we look into it more deeply. Out of curiosity, I decided to see what Copilot could do in this new area, and I was happy with what I found.

## Open Mic / Curiousity Experiment:
So my little experiment was to post a EDI 96A invoice message and wanted the basic meta data pulled out of message into readable text. To extract the basic metadata from an EDI 96A invoice message and convert it into readable text, you would typically use an EDI parser or translator that understands the EDI standards and can map the segments and elements of the message to human-readable form.

**Input Data**:

```
UNA:+.? ' 
UNB+UNOA:1+5056013218685:14+1111111111111:14+220802:0737+8++ORDERS' 
UNH+1+ORDERS:D:96A:UN' 
BGM+220+PO000224267' 
DTM+63:20220719:102' 
DTM+64:20220719:102' 
DTM+137:20220719:102' 
NAD+BY+5056013218685::9++FENWICK' 
NAD+SU+1111111111111::9++BUSINESS' 
NAD+DP+KLW-DC::92++Killingworth+Fenwick Warehouse, 16 Mylord Cres+Newcastle upon Tyne++NE12 5SP+GBR' 
LIN+1+1+018084851050:EN' 
PIA+1+A220332:BP+A3W0010000:SA' 
IMD+F++:::Item Description' 
IMD+C+98+NS::91' 
QTY+21:5:EA' 
PRI+AAA:12.31' 
LIN+2+1+018084891650:EN' 
PIA+1+A221143:BP+A8AL010000:SA' 
IMD+F++:::Item Description' 
IMD+C+98+NS::91' 
QTY+21:5:EA' 
PRI+AAA:12.048' 
LIN+3+1+018084020906:EN' 
PIA+1+A221232:BP+AX62010000:SA' 
IMD+F++:::Item Description' 
IMD+C+98+NS::91' 
QTY+21:5:EA' 
PRI+AAA:18.334' 
LIN+4+1+018084012864:EN' 
PIA+1+A221435:BP+AW41014000:SA' 
IMD+F++:::Item Description' 
IMD+C+98+NS::91' 
QTY+21:5:EA' 
PRI+AAA:17.286' 
LIN+5+1+018084922439:EN' 
PIA+1+A221491:BP+AEAJ010000:SA' 
IMD+F++:::Item Description' 
IMD+C+98+NS::91' 
QTY+21:5:EA' 
PRI+AAA:38.5' 
LIN+6+1+018084811108:EN' 
PIA+1+A222367:BP+A1K8010000:SA' 
IMD+F++:::Item Description' 
IMD+C+98+NS::91' 
QTY+21:5:EA' 
PRI+AAA:53.428' 
LIN+7+1+018084950104:EN' 
PIA+1+A222369:BP+AHWY010000:SA' 
IMD+F++:::Item Description' 
IMD+C+98+NS::91' 
QTY+21:5:EA' 
PRI+AAA:4.714' 
LIN+8+1+018084977323:EN' 
PIA+1+A221818:BP+AMFT010000:SA' 
IMD+F++:::Item Description' 
IMD+C+98+OS::91' 
QTY+21:5:EA' 
PRI+AAA:61.808' 
UNS+S' 
UNT+58+1' 
UNZ+1+8' 
```

So what leveraging the GPT connector to decode the message

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu4cio6iqcrf1scwwnuo.png)


The flow looks something like this. 

![flowsetup](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExeGlodGlqZ28yaG4wcm56bnFiYXpvN2s1NmtzdHBiMHpycmoxdWQ1dSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/cAj7z86q9VG8zxsEhi/giphy.gif)


![flowoutput](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExNXExbnM2Y2dpeDVicmljZjZxb3JqbjdzOWF4djhzOGs2dGJmMWxrNiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/YIg8hDjIEL9zOqw3CZ/giphy.gif)

TADA !!! the human readable output 

```
The given text is an invoice information that includes details about a purchase order. The invoice contains the following information:

- The invoice number is PO000224267.
- The order was placed on July 19, 2022.
- The buyer is FENWICK, with the identification number 5056013218685.
- The supplier is BUSINESS, with the identification number 1111111111111.
- The delivery address is Killingworth Fenwick Warehouse, 16 Mylord Cres, Newcastle upon Tyne, NE12 5SP, GBR.
- The invoice includes multiple line items with their respective details:
  - Item 1: Description, quantity of 5, and price of 12.31.
  - Item 2: Description, quantity of 5, and price of 12.048.
  - Item 3: Description, quantity of 5, and price of 18.334.
  - Item 4: Description, quantity of 5, and price of 17.286.
  - Item 5: Description, quantity of 5, and price of 38.5.
  - Item 6: Description, quantity of 5, and price of 53.428.
  - Item 7: Description, quantity of 5, and price of 4.714.
  - Item 8: Description, quantity of 5, and price of 61.808.

This summary provides an overview of the invoice information, including the order details, buyer and supplier information, delivery address, and the line items with their respective quantities and prices.
```

**Consideration**:

- Custom trading partner mapping is not extracted
- Some of the terms and condition of the invoice were not extracted and the way to capture would be improving the prompt. 
- This is just for initial analysis of the EDI interface and not the complete mapping. The costing to leverage a Co-Pilot service would expensive
- More compute and not sustainable, as AI service is a generic model where as the EDI translating software are built specific to this job