NextGen Knowledge Center

Adding Segments to a Message

Segments are a group of fields that can contain varying types of data. Each segment exists independently and can be used in multiple messages.

To add a segment to a message, create a new XML object with a segment code, then add it after the segment it should follow:

var seg = new XML("<ZZZ><ZZZ.1><ZZZ.1.1>My Value</ZZZ.1.1></ZZZ.1></ZZZ>");
msg['QRF'] += seg;

Insert the += operator into a message after a particular segment or at the end of the message. Mirth® Connect has four global functions by which you can create segments for messages:

FunctionFunction DescriptionExample
Create Segment (individual)Creates an XML object for the segment that has not been inserted into a message.
var newSeg = createSegment('ZYX');
newSeg ['ZYX']['ZYX.1']['ZYX.1.1'] = "My Value";
msg += newSeg;
Create Segment (in message)Creates an XML object for the segment at the end of a specified message.
createSegment ('ZYX', msg);
msg ['ZYX']['ZYX.1']['ZYX.1.1'] = "My Value"; 
Create Segment (in message, index)

Creates an XML object for the segment in a specified message (msg or tmp) in a specified index and is issued for repeating segments; if a segment is already in the index, the new segment overwrites it.

createSegment ('OBX', msg, 4);
msg ['OBX'][4]['OBX.3']['OBX.3.2'] = "Glucose";
Create Segment After SegmentCreates an XML object for the segment and adds it after the target segment.
createSegmentAfter("ZZZ", msg ["QRF"]);
msg ["ZZZ"]["ZZZ.1"]["ZZZ.1.1") = "My Value";

which function call is equivalent to:

msg ["QRF"] += createSegment("ZZZ");
To access these functions, navigate to an Edit Channel page > Channel Tasks panel > Edit Filter or Edit Transformer. On the Reference tab, select the Category bar > Message Functions, among which you will find the Create Segment functions. For additional information, see Reference List.
Image showing how to add a segment to a message