I have this in PID-3:
1235-1232544^^^GEHC^AN~123^^^GEHC^MR~888-88-8888^^^GEHC^SS~1233-1231331^^^GEHC^PI
Use the the following code:
var pid3Count = StringUtils.splitByWholeSeparator(message.getNode('PID-3'), '~').length;
for (var i = pid3Count; i > 0; i--) {
var pid3 = message.getNode('PID-3[' + i + ']');
if (StringUtils.endsWithIgnoreCase(pid3, 'MR')) {
message.removeFirstNode('PID-3[' + i + ']');
}
}
message.setNode('PID-3', StringUtils.replace(message.getNode('PID-3'), '~~', '~'));
This is the result:
1235-1232544^^^GEHC^AN~888-88-8888^^^GEHC^SS~1233-1231331^^^GEHC^PI