Little help getting started.

321 views
Skip to first unread message

wayne...@hotmail.com

unread,
Jun 4, 2014, 7:10:16 AM6/4/14
to bots...@googlegroups.com
Hi,

I'm pretty new to bots, Python and EDI in general. What I'm trying to do is translate EDIFACT messages into JSON (I'll use XML if it's easier) so that I can process them. The messages are IFCSUM, IFTSTA & IFTMIN.
  • I've setup Channels and these are working fine.
  • I've downloaded the relevant D96A grammars from Source Forge and I've added them to my edifact grammar folder.
  • I've created a route called IFTMIN2JSON. FromEdiType: edifact. FromMessageType: edifact.
  • I setup a translation and copied one of the mapping scripts from one of the example plugins. This mapping script is supposed to deal with ORDER messages (obviously, this won't work for me and I'll need to change it up). My translation is currently set to FromEditType: edifact, FromMessageType: IFTMIND96AUNDEFO04 - ToEditType: json, ToMessageType: IFTMIND96AUNDEFO04
Questions:

In regards to grammars; what do I place in the grammars/json folder. Is it OK for me to upload the D96A grammars to this folder as well, or am I mistaken here? I'm kind of confused about what type of grammars should go into the json (or XML) grammar folders.

After running bots, I receive the error "MessageError: [G50]: Grammar "C:\Python27\lib\site-packages\bots\usersys\grammars\json\IFTMIND96AUNDEFO04" starts with record "UNH"; but while reading edi-file found start-record "HEA". Is this related to the fact that I'm using a mapping script that is supposed to be dealing with ORDER messages?

Any help or pointers would be very much appreciated,
Wayne.







henk-jan ebbers

unread,
Jun 4, 2014, 7:37:50 AM6/4/14
to bots...@googlegroups.com
hi Wayne,

welcome to bots mailing list.

you have a translation rule.
the mapping script you use in this translation rule produces output that starts with record 'HEA'.
but the grammar of the ToMessageType you provide in the translation rule says it should start with 'UNH'.

hope this helps,
henk-jan
--
You received this message because you are subscribed to the Google Groups "Bots Open Source EDI Translator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to botsmail+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wayne...@hotmail.com

unread,
Jun 4, 2014, 11:59:26 AM6/4/14
to bots...@googlegroups.com
Hi eppye,

Thanks for the feedback. I've managed to push on and get somewhere. However, I'm doing something wrong; most likely because I've failed to grasp a vital concept. In my mapping file, I've managed to accommodate the UNH segment. However, now I'm trying to tackle the BGM segment. See example below:

out.put({'BOTSID':'UNH','0062': inn.get({'BOTSID':'UNH', '0062': None})})
out.put({'BOTSID':'UNH','S009.0065': inn.get({'BOTSID':'UNH', 'S009.0065': None})})
out.put({'BOTSID':'UNH','S009.0052': inn.get({'BOTSID':'UNH', 'S009.0052': None})})
out.put({'BOTSID':'UNH','S009.0054': inn.get({'BOTSID':'UNH', 'S009.0054': None})})
out.put({'BOTSID':'UNH','S009.0051': inn.get({'BOTSID':'UNH', 'S009.0051': None})})
out.put({'BOTSID':'UNH','S009.0057': inn.get({'BOTSID':'UNH', 'S009.0057': None})})

out.put({'BOTSID':'BGM','C002.1001': inn.get({'BOTSID':'BGM', 'C002.1001': None})})
out.put({'BOTSID':'BGM','C002.1131': inn.get({'BOTSID':'BGM', 'C002.1131': None})})
out.put({'BOTSID':'BGM','C002.3055': inn.get({'BOTSID':'BGM', 'C002.3055': None})})
out.put({'BOTSID':'BGM','C002.1000': inn.get({'BOTSID':'BGM', 'C002.1000': None})})
out.put({'BOTSID':'BGM','1004': inn.get({'BOTSID':'BGM', '1004': None})})
out.put({'BOTSID':'BGM','1225': inn.get({'BOTSID':'BGM', '1225': None})})
out.put({'BOTSID':'BGM','4343': inn.get({'BOTSID':'BGM', '4343': None})})

This results in the error: MessageError: [S03]: Record "UNH-BGM" occurs 0 times, min is 1

BikeMike

unread,
Jun 5, 2014, 5:32:52 AM6/5/14
to bots...@googlegroups.com
On Wednesday, 4 June 2014 20:40:16 UTC+9:30, wayne...@hotmail.com wrote:
Hi,

I'm pretty new to bots, Python and EDI in general. What I'm trying to do is translate EDIFACT messages into JSON (I'll use XML if it's easier) so that I can process them. The messages are IFCSUM, IFTSTA & IFTMIN.

Hi Wayne,
Do you mean you just want to convert the edifact into a json representation of that edifact? ie. no actual mapping of the data in bots, you will do that elsewhere?

For any output from bots, you need an output grammar. You often need to create it yourself because json, xml, csv etc are not EDI standards as such. There are a couple of special types in bots; jsonnocheck and xmlnocheck. These still require a grammar to exist, but it's just an empty file.

There is also a mapping function transform.inn2out(inn,out)

So to achieve what (I think) you want, just create a mapping that calls inn2out, create an empty grammar with suitable name in grammars/json, and set translation out editype to jsonnocheck and messagetype to match the empty grammar. The same method works for xmlnocheck too.

As an example, an edifact order creates json like this
{"UNH": {"CNT": [{"C270.6069": "2", "C270.6066": "8"}], "UNS": [{"0081": "S"}], "UNT": [{"0062": "17/050687", "0074": "56"}], "NAD": [{"3035": "BY", "C082.3039": "17"}, {"3035": "SU", "C082.3055": "92", "C082.3039": "SCHNEIDER"}], "LIN": [{"1082": "1", "PIA": [{"4347": "1", "C212#1.7143": "VP", "C212#1.7140": "56CSC410-EO"}], "QTY": [{"C186.6060": "1", "C186.6063": "21", "C186.6411": "EA"}], "RFF": [{"C506.1153": "PR", "C506.1154": "40016357"}], "MOA": [{"C516.5025": "203", "C516.5004": "110.26"}], "IMD": [{"7077": "F", "C273.7008#1": "EXTENSION SOCKET 4 PINS 500V 10A"}]}, {"1082": "2", "PIA": [{"4347": "1", "C212#1.7143": "VP", "C212#1.7140": "56CSC420-EO"}], "QTY": [{"C186.6060": "1", "C186.6063": "21", "C186.6411": "EA"}], "RFF": [{"C506.1153": "PR", "C506.1154": "40016357"}], "MOA": [{"C516.5025": "203", "C516.5004": "91.28"}], "IMD": [{"7077": "F", "C273.7008#1": "EXTENSION SOCKET 4 PINS 500V 20A"}]}, {"1082": "3", "PIA": [{"4347": "1", "C212#1.7143": "VP", "C212#1.7140": "56E2-GY"}], "QTY": [{"C186.6060": "2", "C186.6063": "21", "C186.6411": "EA"}], "RFF": [{"C506.1153": "PR", "C506.1154": "40016357"}], "MOA": [{"C516.5025": "203", "C516.5004": "46.44"}], "IMD": [{"7077": "F", "C273.7008#1": "ENCLOSURE MOUNTING 2 GANG"}]}, {"1082": "4", "PIA": [{"4347": "1", "C212#1.7143": "VP", "C212#1.7140": "56K2SW120-GY"}], "QTY": [{"C186.6060": "1", "C186.6063": "21", "C186.6411": "EA"}], "RFF": [{"C506.1153": "PR", "C506.1154": "40016357"}], "MOA": [{"C516.5025": "203", "C516.5004": "125.44"}], "IMD": [{"7077": "F", "C273.7008#1": "KEY SWITCH"}]}, {"1082": "5", "PIA": [{"4347": "1", "C212#1.7143": "VP", "C212#1.7140": "56L2-GY"}], "QTY": [{"C186.6060": "1", "C186.6063": "21", "C186.6411": "EA"}], "RFF": [{"C506.1153": "PR", "C506.1154": "40016357"}], "MOA": [{"C516.5025": "203", "C516.5004": "12.78"}], "IMD": [{"7077": "F", "C273.7008#1": "LID FOR MOUNTING ENCLOSURE 2 GANG"}]}, {"1082": "6", "PIA": [{"4347": "1", "C212#1.7143": "VP", "C212#1.7140": "56P410-EO"}], "QTY": [{"C186.6060": "1", "C186.6063": "21", "C186.6411": "EA"}], "RFF": [{"C506.1153": "PR", "C506.1154": "40016357"}], "MOA": [{"C516.5025": "203", "C516.5004": "32.48"}], "IMD": [{"7077": "F", "C273.7008#1": "INDUST PLUG 500V 10A 4R PINS"}]}, {"1082": "7", "PIA": [{"4347": "1", "C212#1.7143": "VP", "C212#1.7140": "56P420-EO"}], "QTY": [{"C186.6060": "1", "C186.6063": "21", "C186.6411": "EA"}], "RFF": [{"C506.1153": "PR", "C506.1154": "40016357"}], "MOA": [{"C516.5025": "203", "C516.5004": "35.65"}], "IMD": [{"7077": "F", "C273.7008#1": "INDUST PLUG 500V 20A 4R PINS"}]}, {"1082": "8", "PIA": [{"4347": "1", "C212#1.7143": "VP", "C212#1.7140": "56POK"}], "QTY": [{"C186.6060": "1", "C186.6063": "21", "C186.6411": "EA"}], "RFF": [{"C506.1153": "PR", "C506.1154": "40016357"}], "MOA": [{"C516.5025": "203", "C516.5004": "4.99"}], "IMD": [{"7077": "F", "C273.7008#1": "PENDANT OUTLET KIT"}]}], "BGM": [{"C106.1004": "17/050687", "C002.1001": "220", "1225": "9"}], "S009.0054": "93A", "S009.0051": "UN", "S009.0052": "D", "S009.0065": "ORDERS", "DTM": [{"C507.2005": "4", "C507.2379": "102", "C507.2380": "20130415"}], "0062": "17/050687"}}

Kind Regards,
Mike

wayne...@hotmail.com

unread,
Jun 5, 2014, 6:03:50 AM6/5/14
to bots...@googlegroups.com
Hi BikeMike, thanks for the reply!

no actual mapping of the data in bots, you will do that elsewhere?

Yes, I would prefer to handle the data in another part of my system, which will carry out the actual business logic. On file, I have JSON data describing each segment, which will be useful in converting the likes of C082.3039 into their English equivalent: "partyIdentifier" etc.

Question: Will this work from JSON to EDIFact as well?

Also, do you have an example of how to use transform?

def main(inn,out):
    transform.inn2out(inn,out)

is giving me a user script error, which says "NameError: global name 'transform' is not defined".

BikeMike

unread,
Jun 5, 2014, 6:10:20 AM6/5/14
to bots...@googlegroups.com
I think this will work from json to edifact, but not sure. I will try jsonnocheck as input.

You need to import transform...
import bots.transform as transform
def main(inn,out):
    transform.inn2out(inn,out)


henk-jan ebbers

unread,
Jun 5, 2014, 6:18:55 AM6/5/14
to bots...@googlegroups.com
hi Mike,

do not use jsonnocheck or xmlnocheck as input.
bots tries to 'guess' what is record/what is field. (in same way as xmltogrammar does).
edi is about business data, you do not want 'guessing'.
(in fact I can make xmlnocheck files that are quite similar, give different results. so consider this 'instable')


kind regards,
henk-jan

BikeMike

unread,
Jun 5, 2014, 6:26:37 AM6/5/14
to bots...@googlegroups.com
Yes I definitely agree. Input files should always have a complete grammar. But for testing this did work ok (edifact -> jsonnocheck then fed back through jsonnocheck -> edifact). Just had to set the partners.

Maybe it's a good idea to prevent the "nocheck" types being used for input?

henk-jan ebbers

unread,
Jun 5, 2014, 6:39:30 AM6/5/14
to bots...@googlegroups.com
think you are right. that should not be possible. Will look if that is easy to do.

for one-on-one translations:
I have done things like using the edifact grammars as eg fixed files.
but grammars have to be edited as only edifact handles sub-elements.
it should be possible to change grammar.py in a way that sub-fields end up like fields (and handle the M/C for composite and sub-elements)

kind regards,
henk-jan


On 06/05/2014 12:26 PM, BikeMike wrote:
Yes I definitely agree. Input files should always have a complete grammar. But for testing this did work ok (edifact -> jsonnocheck then fed back through jsonnocheck -> edifact). Just had to set the partners.

Maybe it's a good idea to prevent the "nocheck" types being used for input?

wayne...@hotmail.com

unread,
Jun 5, 2014, 7:38:44 AM6/5/14
to bots...@googlegroups.com
Thanks for the reply!

Have you see this before? "UnicodeEncodeError: 'charmap' codec can't encode character u'\x7b' in position 0: character maps to <undefined>"

BikeMike

unread,
Jun 5, 2014, 6:33:20 PM6/5/14
to bots...@googlegroups.com
That means there is a character in the file that does not match the charset specified in the grammar (or default).
https://code.google.com/p/bots/wiki/Charsets
Reply all
Reply to author
Forward
0 new messages