IPWorks EDIFACT 2020 JavaScript Edition

Questions / Feedback?

Translate Method

Translates the specified data.

Syntax

async edifacttranslator.translate(): Promise<void>

Remarks

This method translates the specified data.

The class will convert a document from the format specified by InputFormat to the format specified by OutputFormat. In practice this allows for converting to XML or JSON from EDI and vice versa.

Before translating from EDI to XML or JSON it is recommended to load a schema using the LoadSchema method. This ensures additional information can be included in the XML or JSON document. If a schema is specified the XML or JSON will include types and descriptions as element attributes which are useful for interpreting the data.

EDI elements may optionally be renamed when creating XML. To define how an element is renamed add a renaming rule by calling AddRenamingRule.

After calling Translate the resulting output will contain the EDI, XML or JSON data as defined by OutputFormat. If the output data is XML the ExportXMLSchema method may be called to export a schema (.xsd) defining the structure of a valid XML document. XML documents which adhere to this document may be translated from XML to EDI.

Input and Output Properties

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:
  • OutputFile
  • OutputData: The output data is written to this property if no other destination is specified.

Example - Translating EDIFACT to XML


Edifacttranslator translator = new Edifacttranslator();

translator.InputFormat = EdifacttranslatorInputFormats.ifEDIFACT;
translator.OutputFormat = EdifacttranslatorOutputFormats.ofXML;

translator.InputFile = "EDIFACT_D97A_INVOIC.edi";
translator.OutputFile = "EDIFACT_D97A_INVOIC.xml";

translator.SchemaFormat = EdifacttranslatorSchemaFormats.schemaJSON;
translator.LoadSchema("RSSBus_D97A_INVOIC.json");

translator.Translate();

The code above creates an XML document with content like:

<Interchange Delimiters=":+.?*&apos;" xmlns="http://www.nsoftware.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Meta>
        <UNB1 type="Composite" desc="SYNTAX IDENTIFIER">
            <UNB1.1 desc="Syntax identifier">UNOB</UNB1.1>
            <UNB1.2 desc="Syntax version number">1</UNB1.2>
        </UNB1>
        <UNB2 type="Composite" desc="INTERCHANGE SENDER">
            <UNB2.1 desc="Interchange sender identification">WAYNE_TECH</UNB2.1>
        </UNB2>
        <UNB3 type="Composite" desc="INTERCHANGE RECIPIENT">
            <UNB3.1 desc="Interchange recipient identification">ACME</UNB3.1>
        </UNB3>
        <UNB4 type="Composite" desc="DATE AND TIME OF PREPARATION">
            <UNB4.1 desc="Date">160707</UNB4.1>
            <UNB4.2 desc="Time">1547</UNB4.2>
        </UNB4>
        <UNB5 desc="Interchange control reference">000000002</UNB5>
        <UNB6 type="Composite" desc="RECIPIENT&apos;S REFERENCE/PASSWORD DETAILS">
            <UNB6.1 desc="Recipient reference/password"/>
        </UNB6>
        <UNB7 desc="Application reference">1234</UNB7>
        <UNB8 desc="Processing priority code"/>
        <UNB9 desc="Acknowledgement request"/>
        <UNB10 desc="Interchange agreement identifier"/>
        <UNB11 desc="Test indicator">1</UNB11>
    </Meta>
    <TransactionSet>
        <TX-D97A-INVOIC type="TransactionSet">
            <Meta>
                <UNH1 desc="MESSAGE REFERENCE NUMBER">509010117</UNH1>
                <UNH2 type="Composite" desc="MESSAGE IDENTIFIER">
                    <UNH2.1 desc="Message type identifier">INVOIC</UNH2.1>
                    <UNH2.2 desc="Message type version number">D</UNH2.2>
                    <UNH2.3 desc="Message type release number">97A</UNH2.3>
                    <UNH2.4 desc="Controlling agency">UN</UNH2.4>
                </UNH2>
            </Meta>
            <BGM type="Segment">
                <BGM01 type="Composite" desc="DOCUMENT/MESSAGE NAME">
                    <BGM0101 desc="Document/message name, coded">380</BGM0101>
                    <BGM0102 desc="Code list qualifier"/>
                    <BGM0103 desc="Code list responsible agency, coded"/>
                    <BGM0104 desc="Document/message name">TAX INVOICE</BGM0104>
                </BGM01>
...                

Example - Translating EDIFACT to JSON


Edifacttranslator translator = new Edifacttranslator();

translator.InputFormat = EdifacttranslatorInputFormats.ifEDIFACT;
translator.OutputFormat = EdifacttranslatorOutputFormats.ofJSON;

translator.InputFile = "EDIFACT_D97A_INVOIC.edi";
translator.OutputFile = "EDIFACT_D97A_INVOIC.json";

translator.SchemaFormat = EdifacttranslatorSchemaFormats.schemaJSON;
translator.LoadSchema("RSSBus_D97A_INVOIC.json");

translator.Translate();

The code above creates a JSON document with content like:

{
	"meta": {
		"type": "Interchange",
		"delimiters": ":+.?*'",
		"UNB1": {
			"type": "Composite",
			"desc": "SYNTAX IDENTIFIER",
			"UNB1.1": {
				"desc": "Syntax identifier",
				"value": "UNOB"
			},
			"UNB1.2": {
				"desc": "Syntax version number",
				"value": "1"
			}
		},
		"UNB2": {
			"type": "Composite",
			"desc": "INTERCHANGE SENDER",
			"UNB2.1": {
				"desc": "Interchange sender identification",
				"value": "WAYNE_TECH"
			}
		},
		"UNB3": {
			"type": "Composite",
			"desc": "INTERCHANGE RECIPIENT",
			"UNB3.1": {
				"desc": "Interchange recipient identification",
				"value": "ACME"
			}
		},
		"UNB4": {
			"type": "Composite",
			"desc": "DATE AND TIME OF PREPARATION",
			"UNB4.1": {
				"desc": "Date",
				"value": "160707"
			},
			"UNB4.2": {
				"desc": "Time",
				"value": "1547"
			}
		},
		"UNB5": {
			"desc": "Interchange control reference",
			"value": "000000002"
		},
		"UNB6": {
			"type": "Composite",
			"desc": "RECIPIENT'S REFERENCE\/PASSWORD DETAILS",
			"UNB6.1": {
				"desc": "Recipient reference\/password",
				"value": ""
			}
		},
		"UNB7": {
			"desc": "Application reference",
			"value": "1234"
		},
		"UNB8": {
			"desc": "Processing priority code",
			"value": ""
		},
		"UNB9": {
			"desc": "Acknowledgement request",
			"value": ""
		},
		"UNB10": {
			"desc": "Interchange agreement identifier",
			"value": ""
		},
		"UNB11": {
			"desc": "Test indicator",
			"value": "1"
		}
	},
	"transactionsets": [{
		"meta": {
			"type": "TransactionSet",
			"UNH1": {
				"desc": "MESSAGE REFERENCE NUMBER",
				"value": "509010117"
			},
			"UNH2": {
				"type": "Composite",
				"desc": "MESSAGE IDENTIFIER",
				"UNH2.1": {
					"desc": "Message type identifier",
					"value": "INVOIC"
				},
				"UNH2.2": {
					"desc": "Message type version number",
					"value": "D"
				},
				"UNH2.3": {
					"desc": "Message type release number",
					"value": "97A"
				},
				"UNH2.4": {
					"desc": "Controlling agency",
					"value": "UN"
				}
			}
		},
		"segments": [{
			"type": "Segment",
			"name": "BGM",
			"BGM01": {
				"type": "Composite",
				"desc": "DOCUMENT\/MESSAGE NAME",
				"BGM0101": {
					"desc": "Document\/message name, coded",
					"value": "380"
				},
				"BGM0102": {
					"desc": "Code list qualifier",
					"value": ""
				},
				"BGM0103": {
					"desc": "Code list responsible agency, coded",
					"value": ""
				},
				"BGM0104": {
					"desc": "Document\/message name",
					"value": "TAX INVOICE"
				}
			},
...            

 
 
Copyright (c) 2021 /n software inc. - All rights reserved.
IPWorks EDIFACT 2020 JavaScript Edition - Version 20.0 [Build 7721]