Creating HL Segments
From a flat file, I'm attempting to create an X12 856. The flat file is a 945 without HL segments and the X12 is an 856 with HL segments and I don't know much of anything about how the 856 functions.
I looked up the construction of the segment and found that the HL01 increments through out the file and the HL02 refers to previous HL01s as a Parent.
Based on the sample 856 I'm looking at, the HL02 refers to the previous parent anytime there's a new item which leads me to believe that each item is considered to be a package in this 856.
My question is how to map the HL02 segment? Is it a series of containers that refer back to previous elements? If so, how do I reference them?
I did find the following discussion on the topic, but it was never resolved.
Comments
I've been thinking through this and I think what needs to happen is a transformation that will create the HL segments. I'm working through that and will give my feedback unless someone else is able to provide a possible solution.
Thanks for any and all assistance.
Jack Harris it looks like you will need to calculate this in a script (preMap on import or preSavePage on export) prior to getting to the EDI building translation. I haven't dealt with these 856s before, but the structure is weird since everything is put into HL and not some other segment for the packs. Since it's not in it's own sub segment, it forces you to create this parent level reference.
You wouldn't happen to be able to help me find a starting point or seed code that I could build from, would you?
Jack Harris what does your sample output look like?
Jack Harris you should try and give Celigo AI a go. It gave me this with the first prompt. I'm assuming each ST object you have goes to a HL and then LX to sub of HL (not completely sure what you need, but you can adjust).
Prompt:
Can you go through each ST object and each LX object and add a sequential counter called "Hierarchical ID Number". Then for each LX object, can you add a field called "Hierarchical Shipment Parent ID Number" and the value of it will be the value of the "Hierarchical ID Number" within the ST object outside of itself
Script:
Where are you putting this?
Also, I get errors every time I attempt to use Celigo AI. The handlebar code especially errors out every time.
Jack Harris it's a preMap script on the import, but you could rework it to put it on a preSavePage script on export as well.
so to break your code down into pseudo-code
In effect, the HL ID will continue to increase and the LX's parent will equal the previous counter. So for the sub loops, I'd just add another st.*.forEach loop?
Jack Harris yeah if you have even deeper loops after LX you can keep nesting forEach loops and referencing parent counts.
I restructured it so that I could get the right HL loops and used the AI to get code for it but I'm getting a prompt when I use the code.
Here's what I put into the AI:
Can you go through each HLS object and each HLO object and add a sequential counter called "Hierarchical ID Number". Then for each HLO object, can you add a field called "Hierarchical Shipment Parent ID Number" and the value of it will be the value of the "Hierarchical ID Number" within the ST object outside of itself
Here's the restructured sample data:
Jack Harris your HLS segment is not an array, it's just an object. So you don't have anything to loop through there.
When I turn them into [object]'s the previewed data goes away.
Jack Harris HLO is also not an array in your sample data. I made it an array and used the prompt you gave for Celigo AI and the output looks right.
So, if I want to add levels, I'd do it like this, yes?
Code:
Test data
Jack Harris yeah it would be something like that. With each level, you may need a different counter. Like if your third level needs a reference to the second level, then you would need a second level counter as opposed to just your first level counter. Not sure if that's the case, but just calling it out.
I tried using the AI Query you used and this was my result.
Code:
Function Input
Jack Harris I would try to reprompt the AI with your new data structure. "d.HLS" is not a valid path because d.HLS does not exist in your data structure, but it did exist in a prior structure you shared. Your correct path for this structure would be d.ISA.GS.ST.HLS.
That got it working to preview correctly, but when I try to run the test nothing goes through.
Jack Harris if you copy the input of the test run and put it in the input of the script preview, does it work there? Can you provide script and both inputs as well if it is working in preview?
Mock Output from the Export
After the transformation
Script
Script Output in the preview
Function Input
Function Output
Please sign in to leave a comment.