web stats
Batch processing edi 834 files - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #11  
Old 07-17-2017, 08:28 AM
rav rav is offline
Mirth Guru
 
Join Date: Oct 2012
Posts: 258
rav is on a distinguished road
Default

Quote:
Originally Posted by kirbykn2 View Post
I did something similar for an X12 file. I set "Process Batch" to yes on the summary tab, then configured the "Batch Delimiter" in "Set Data Types".

I have similar set up with following code in batch script and it takes ages to run and it spits out just one message and after that I see heapspace error

var segDelim = '~';
var elementDelim = '*';
var subelementDelim = ':';
var infer = true;

var message = new java.lang.StringBuilder();
var ch;
while ((ch = consume(1)) != null) {
if (infer) {
elementDelim = consume(3);
subelementDelim = consume(101);
segDelim = consume(1);
consumeNewline();
infer = false;
continue;
} else if (ch == segDelim) {
consumeNewline();
reader.mark(3);
if (readChar() == 'I' && readChar() == 'N' && readChar() == 'S') {
reader.reset();
break;
}
reader.reset();
}
}

return message.toString();

function readChar() {
var c = reader.read();
return c == -1 ? null : java.lang.Character.valueOf(c);
}

function consume(num) {
var ch;
for (var i = 1; i <= num; i++) {
ch = readChar();
if (ch != null) {
message.append(ch);
}
}
return ch;
}

function consumeNewline() {
reader.mark(1);
var ch = readChar();
if (ch == '\r') {
message.append(ch);
reader.mark(1);
if ((ch = readChar()) == '\n') {
message.append(ch);
} else {
reader.reset();
}
} else if (ch == '\n') {
message.append(ch);
} else {
reader.reset();
}
}
Reply With Quote
  #12  
Old 05-22-2019, 05:02 AM
ashishshetty1992 ashishshetty1992 is offline
Mirth Newb
 
Join Date: Jan 2018
Location: Boston
Posts: 17
ashishshetty1992 is on a distinguished road
Default

The script in Split Batch By JavaScript should be as simple as this. Set data type to "Raw".
Code:
var line = '';
var message = '';
var array;
var header;

while (line = reader.readLine()) {
    header = line.substring(0, line.indexOf('~INS')) + '~\n';
    array = line.split('~');
    for (var i in array) {
        if (array[i].substring(0, 3) == 'INS') {
            message += '---\n' + header + array[i] + '~\n';
        } else {
            message += array[i] + '~\n';
        }
    }
}

return message;
PS: The "---\n" is only to separate each INS group. You can take that out if you wish.
Reply With Quote
Reply

Tags
batch process, edi 834, javascript

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:07 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation