The following methods are available within the JavaScript filter to allow access to the Symphonia Parsing Engine.

  • JSROMessage.getReadableEdiMessage()
  • JSMessage.getWritableEdiMessage()

These methods both retrieve the root com.orion.symphonia3.MessageElement object representing the entire parsed message. The Symphonia API can then be used to browse and modify the message.

The difference between the methods is that the readable version must not be used to change the message at all. Any changes made using the parsed message returned from this method may be discarded. The writable version should be used when changes need to be made.

Any changes made to the message are written out either when the filter processing completes, or if the text or body property is requested subsequently in the JavaScript. Both of these messages throw an exception if the message is not parsing with any of the EDI message definitions on the route. For example:

// Add the output message
var next = output.append(input[0]);

// Get the writable message and MSH segment
var msg = next.getWritableEdiMessage();
var msh = msg.getElementAt("MSH");

// Set the sender
msh.getElementAt("SendingApplication").setValue("EDI Explorer");
msh.getElementAt("SendingFacility").setValue("Rhapsody Org");

Advanced message handling is available by utilizing the getWritableEdiMessage object. Details of the functionality available can be found in the EDI documentation for the MessageElement interface. This documentation is normally located at <Rhapsody IDE Install Directory>\EDI\Java Engine\docs\blank.html.

For example, a segment may be removed from the message as follows:

var msg = next.getWritableEdiMessage();

// Iterate through all the orders and all the results to find the invalid results and store the element index of each.
 
// Delete in reverse order as elements are moved forward when one is deleted.
invalidResults.reverse();
for (var i = 0; i < invalidResults.length; i++) {
	var index = invalidResults[i];
	var results = msg.getElementAt("Order[" + index.orderIndex + "]/Results");
 
    // Remove invalid results element.
	results.removeElementAt(index.resultIndex); 
}