Loop Section returns entire document
I am trying to return a specific section of the EDI file so I can loop it and make use of it.
Following a snippet I found I return an object however, it's the entire document and not the section I am interested in.
var x12Stream = getFile(theFile);
List<IEdiItem> ediItems = new List<IEdiItem>();
using (var ediReader = new X12Reader(x12Stream, LoadFactory, new X12ReaderSettings() { ContinueOnError = true }))
{
var myloop = new List<Loop_PO1_850>();
while (ediReader.Read())
{
var msg = ediReader.Item as TS850;
if (msg != null)
{
if(msg.IsPart)
{
myloop.AddRange(msg.PO1Loop);
}
else
{
msg.PO1Loop.AddRange(myloop);
ediItems.Add(msg);
myloop.Clear();
}
}
else
{
ediItems.Add(ediReader.Item);
}
}
}
Comments
5 comments
Hello,
Which loops do you need to batch together - on file level, interchange level, group level or transaction level ?
For small files you can do:
ediItems will then hold all PO1 loops across all groups, interchanges and 850 transactions in the file.
For large files, as I see you must have configured splitting by loop po1 in the template, you can do:
po1Loops holds all PO1 loops across all interchanges, groups and 850 transactions in the file.
This is helpful and moved me forward.
Thank you for the fast response!
Looking around the website I see many examples but, not an API documentation.
Is there one available and can you give me a link?
THX
API Reference
Thank you.
When grabbing the CTT however I am getting an error ( same basic code )
[code]
List<Loop_CTT_850> ctt = new List<Loop_CTT_850>();
using (var ediReader = new X12Reader(ediStream, LoadFactory, new X12ReaderSettings() { ContinueOnError = true }))
{
while (ediReader.Read())
{
var _ctt = ediReader.Item as TS850;
if (_ctt != null)
{
ctt.AddRange(_ctt.CTTLoop);
}
}
}
[/code]
I find CTTLoop in the 004010 template with Loop_CTT_850.
I also tried just CTT.
Thanks for any advice.
If I can get a proof of concept to work we are definitely going to buy this tool.
List<Loop_CTT_850> ctt = new List<Loop_CTT_850>();
using (var ediReader = new X12Reader(ediStream, LoadFactory, new X12ReaderSettings() { ContinueOnError = true }))
{
while (ediReader.Read())
{
var _ctt = ediReader.Item as TS850;
if (_ctt != null)
{
ctt.Add(_ctt.CTTLoop);
}
}
}
Please sign in to leave a comment.