I'm working on our outgoing 856 translation but I've run into an issue with the order of the segments. The PRF segment is supposed to appear between HL at the order level and the HL at the pack level. I'm using the standard 856004010 grammar. I've put the translation below. Any help would be greatly appreciated. Thanks, Kevin
#mapping-script
import bots.transform as transform
import time
def main(inn,out):
#sender, receiver is correct via QUERIES in grammar.
out.put({'BOTSID':'ST','ST01':'856','ST02':out.ta_info['reference'].zfill(4)})
out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN01':'00'})
out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN02':inn.get({'BOTSID':'message','bolnumber':None})})
out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN03':time.strftime('%Y%m%d')})
out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN04':time.strftime('%H%M')})
out.put({'BOTSID':'ST'},{'BOTSID':'HL','HL01':'1'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL','HL02':''})
out.put({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'S'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'TD1','TD101':'PLT90'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'TD1','TD102':inn.get({'BOTSID':'message','numpallets':None})})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'TD1','TD106':'G'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'TD1','TD107':inn.get({'BOTSID':'message','grossweight':None})})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'TD1','TD108':'LB'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'TD5','TD503':'PRLA'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'TD5','TD504':'M'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'TD5','TD505':'Purolator Freight'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'REF','REF01':'VR'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'REF','REF02':inn.get({'BOTSID':'message','vendorref':None})})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'REF','REF01':'2I'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'REF','REF02':'xxxx'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'PER','PER01':'DI'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'PER','PER02':'MARTIN VASILEV'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'PER','PER03':'TE'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'DTM','DTM01':'011'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'DTM','DTM02':time.strftime('%Y%m%d')})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'N1','N101':'MA'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'N1','N103':'92'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'N1','N104':inn.get({'BOTSID':'message','storenum':None})})
out.put({'BOTSID':'ST'},{'BOTSID':'HL','HL01':'10'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL','HL02':'1'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'O'})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'PRF','PRF01':inn.get({'BOTSID':'message','docnum':None})})
out.put({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'PRF','PRF04':transform.datemask(inn.get({'BOTSID':'message','docdtm':None}),'CCYY-MM-DD HH:mm','CCYYMMDD')})
itemCnt = 100;
for itm in inn.getloop({'BOTSID':'message'},{'BOTSID':'items'},{'BOTSID':'item'}):
itmnode = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':itemCnt})
itmnode.put({'BOTSID':'HL','HL02':'10'})
itmnode.put({'BOTSID':'HL','HL03':'P'})
itmnode.put({'BOTSID':'HL'},{'BOTSID':'MAN','MAN01':'GM'})
itmnode.put({'BOTSID':'HL'},{'BOTSID':'MAN','MAN02':itm.get({'BOTSID':'item','namenumber':None})})
itmnode.put({'BOTSID':'HL'},{'BOTSID':'N1','N101':'MA'})
itmnode.put({'BOTSID':'HL'},{'BOTSID':'N1','N103':'92'})
itmnode.put({'BOTSID':'HL'},{'BOTSID':'N1','N104':inn.get({'BOTSID':'message','storenum':None})})
itemCnt += 1
for lin in inn.getloop({'BOTSID':'message'},{'BOTSID':'lines'},{'BOTSID':'line'}):
lineCnt = 200;
ponode = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':lineCnt})
ponode.put({'BOTSID':'HL','HL02':'100'})
ponode.put({'BOTSID':'HL','HL03':'I'})
ponode.put({'BOTSID':'HL'},{'BOTSID':'LIN','LIN01':lin.get({'BOTSID':'line','linenum':None})})
ponode.put({'BOTSID':'HL'},{'BOTSID':'LIN','LIN02':'SK'})
ponode.put({'BOTSID':'HL'},{'BOTSID':'LIN','LIN03':lin.get({'BOTSID':'line','sku':None})})
ponode.put({'BOTSID':'HL'},{'BOTSID':'LIN','LIN04':'UP'})
ponode.put({'BOTSID':'HL'},{'BOTSID':'LIN','LIN05':lin.get({'BOTSID':'line','gtin':None})})
ponode.put({'BOTSID':'HL'},{'BOTSID':'SN1','SN102':lin.get({'BOTSID':'line','ordqua':None})})
ponode.put({'BOTSID':'HL'},{'BOTSID':'SN1','SN103':'EA'})
out.put({'BOTSID':'ST'},{'BOTSID':'CTT','CTT01':out.getcountoccurrences({'BOTSID':'ST'},{'BOTSID':'HL'}) }) #bots counts line items
out.put({'BOTSID':'ST'},{'BOTSID':'SE','SE01':out.getcount()+1,'SE02':out.ta_info['reference'].zfill(4)}) #SE01: bots counts the segments produced in the X12 message.