Published 10 Mar 23 3 minute read

How to Validate Files in ION for Seamless Integration with Infor OS Applications

6039 PetFood Ad Update

Recently I came across a requirement to validate files in ION before they are sent to an application in Infor OS such as M3. This article will introduce you to some of the fundamental concepts of how I achieved it. I’ve even included some freebie Python code

Personally, I think this task is essential if you’re connecting exterof which the concepts will work with XMLs and JSONs, but the example in this article focuses on XMLs.es inal parties to Infor OS where you have limited control in enforcing file formats (i.e. you’re not the one doing the coding that produces the file).

if a file is invalid, it should be rejected as early as possible to avoid unessecary processing

Before diving into the details of how to validate your filn Infor OS, let’s quickly review the fundamental methods for pushing and pulling data in and out of the platform. After all, understanding how to transfer data is crucial before delving into the concepts of validating it.

To transmit data to any Infor OS product, it must first go through Infor ION, which is the Intelligent Open Network. Accessing ION is possible via ION Connection Points. Available connection points include:

Among these, file connections (including Enterprise Connectors and (s)FTP) are the most commonly used technologies in implementations. While I plan to explore and write future articles on the other technologies, file connections remain popular because they are easier to work with and use familiar methodologies.

ION Data Catalog – Storing Schemas

In order to validate a file, you need to have a schema that defines the structure and format of the file. One option to store this schema information is to use the ION Desk – Data Catalog – Object Schemas within Infor OS. However, if you prefer to automatically track changes to your schemas at a granular level, GitHub might be a better option.

XMLs validate against XSDs

JSONs validate against JSON Schemas

In my case, I’m validating XMLs against XSDs and my XSD is stored in Object Schemas.

Now that we know what we’re validating against, the next step is to retrieve the schema so that it’s available for processing.

ION API Connection Point

This is where connection points come in handy. You can use one of the standard IONSERVICES APIs to retrieve the XSD from data catalogs.

To do this, you need to configure an API Connection Point that will call an ION API. This retrieves the schema so that it’s available to use as a string. The string can then be fed into a Python script that will look after the processing.

If you’re using Object Schemas to store the schema, your API should look something like this:

ION Scripting – Validation Processing

One thing that makes ION so versatile is the ability to run Python code via ION Desk – Scripting. I developed a script that validates an XML string against an XSD string and generates a JSON string that describes the validation results.

It’s important to note that without the use of a custom library called xmlschema, accomplishing this task in vanilla Python would be quite complex. However, xmlschema streamlines the process and allows for validation in just a few lines of code.

import xmlschema
import json

# 1. Import the XSD from a string
xsdSchema = xmlschema.XMLSchema(inXSDString)

# 2. Declare dictionary that will form outbound JSON string
outHeader = {}

# 3. Try and validate the XML string
try:
# Validate the XML content against the schema
xsdSchema.validate(inXMLString)
outHeader[‘custom_validXML’] = True
except xmlschema.XMLSchemaValidationError as e:
# XML Has failed validation, get the reason why
outHeader[‘custom_validXML’] = False
outHeader[‘custom_invalidXMLReason’] = “‘” + e.elem.tag + “‘ ” + e.reason

# 4. Output data so it can be accessed in a data flow
outHeader = json.dumps(outHeader)
outXMLString = inXSDString
There are a few different libraries you could use for validating XML files against XSD schemas in Python. However, I prefer to use xmlschema because it’s a pure Python library. Additionally, it has a simple and easy-to-use API, which allows you to perform the validation in just a few lines of code.

ION Data Flow

Now that we have an idea of the components that will be used in the validation process, the final step is to integrate them together in a data flow.

A screenshot showing a section of an ION Data Flow.
The important component in this process is the merge section of the dataflow, which takes in two parameters (inXSDString and inXMLString) and outputs two parameters (outXMLString and outHeader).

By setting the JSON containing the validation results as the output header, its key-value pairs can be utilised in subsequent routing.

Implementing the above will provide you with a great starting point on how to validate files as early as possible in Infor OS using ION. Despite only taking a couple of hours to develop, this validation process has already proven to be time-saving when performing integration testing.

For example, when testing a custom integration that updates item master records in M3 (MMS001), I received a rejected acknowledgment file containing the below information:

<ResponseCriteria>
  <ResponseExpression actionCode="Rejected"/>
    <ChangeStatus>
      <Reason>'ItemMaster' Unexpected child with tag 'BaseUOM' at position 17.</Reason>
    </ChangeStatus>
</ResponseCriteria>

This immediately rang alarm bells because I was expecting ItemMaster/BaseUOMCode, not ItemMaster/BaseUOM.

Without that rejection, I might have wasted time trawling through MEC/IEC logs trying to find an answer.

Tip: Keep in mind that the order of elements specified in XSD schemas may be important.

If the order of elements in your XML file does not match the order specified in your XSD, it might not be valid. However, in practice, this should not be an issue since the elements in an XML file are generally not ordered if the schema does not specify an order. To ensure the validity of your XML against the XSD in an unordered fashion, use the tag in your XSD:

<xs:complexType>
  <xs:all>
    <xs:element name="Name"/>
  </xs:all>
</xs:complexType>

Instead of:

<xs:complexType
  <xs:sequence>
    <xs:element name="Name"/>
  </xs:sequence>
</xs:complexType>

In conclusion

Validating files in ION before transmitting them to an application like M3 can play an important role, especially when connecting external parties where you have limited control over file contents.

By using a schema to define the file format, complete file validation can be achieved using APIs and Python in the Intelligent Open Network (ION). Implementing this technology not only saves time during testing cycles but also prevents unnecessary processing of invalid files. However, it’s worth noting that API usage will increase as schemas have to be retrieved for each file that is validated.

If you want to know more about this topic or how to incorporate it into your Infor OS configurations, please don’t hesitate to contact me.

Why IFS choose partners and should you too?

08th Oct 2024
Read More

Top Features and Highlights of Infor CloudSuite.

21st Feb 2024
Read More

Reporting vs Analytics – What is the Difference?

01st Feb 2024
Read More