web stats
Moving DG1 segments after last OBX - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 01-21-2020, 03:47 AM
rutledj rutledj is offline
Mirth Guru
Join Date: Nov 2010
Location: North Carolina
Posts: 399
rutledj is on a distinguished road
Default Moving DG1 segments after last OBX

I can't seem to get this to work. I'm trying to take all of the DG1 segments and move them to be after the last OBX in the message. So far my code only removes them. Can't get them added back in.

var reordered = new XMLList();
var dg1 = new XMLList();
var i = 0;
var kids = msg.children();
var obxIndex = 1;
var obxLen = msg['OBX'].length();
var dg1Group = getSegmentsAfter(msg,msg.MSH,'DG1',false);

//logger.info('obx len ' + obxLen.toString());

// add everything up to but not including the GT1 segment
for each (var child in kids) 
	//logger.info('in for. Name: ' + child.localName());
	if (child.localName() != 'DG1') 
		reordered += child;


var found = false;

//Now add back in the DG1 segments after the last OBX
//find last OBX
if(dg1Group.length > 0)
	//loop backwards to find the last OBX
		if(msg.child(i).name() == 'OBX')
			 for (var j = dg1Group.length-1; j >= 0; j--)
	               found = true;
		if(found == true)

Would appreciate any help. Probably a much more efficient way to do this.
Reply With Quote
Old 01-22-2020, 01:39 PM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,179
agermano is on a distinguished road

var dg1List = msg.DG1;
delete msg.DG1;
msg.OBX[msg.OBX.length()-1] += dg1List;
Reply With Quote
Old 02-27-2020, 01:09 PM
mhaase mhaase is offline
OBX.2 Kenobi
Join Date: Dec 2015
Posts: 62
mhaase is on a distinguished road

That helped me tremendously. Greatly appreciated!

Thank you,
Reply With Quote

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 07:05 AM.

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