web stats
Change field value not working - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 04-12-2012, 04:48 PM
jmjiru jmjiru is offline
Mirth Newb
Join Date: Mar 2012
Posts: 10
jmjiru is on a distinguished road
Exclamation Change field value not working

Hi all,

I am trying to fill a field if it comes in blank by using the word "empty" but when I use logger to read the value, it has an error saying the field.toString() is undefined. I assume that means the value did not get into the field that I was trying to fill. The commented out lines were what I tried. The OBX segment repeats. Here is a code snippet:
for each (obx in msg..OBX){
logger.error("row number = " + rowSize);
var cellCount = 0;
for each (field in msg.OBX.children()){
//Set Id
if (obx['OBX.1'].toString()!= undefined){
if(obx['OBX.1']['OBX.1.1'].toString()!= undefined)
else {
//obx['OBX.1']['OBX.1.1'] = "empty";
logger.error(cells[cellCount].name +", "+ cells[cellCount].value);
Thanks for any help.
Reply With Quote
Old 04-13-2012, 04:59 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
Join Date: Oct 2010
Posts: 6,971
narupley is on a distinguished road

Testing if a field is empty can be tricky because sometimes the field node exists but is empty, and other times the node doesn't exist at all. For example, if you have an OBX segment like "OBX||", then the OBX.1 and OBX.2 nodes will exist in the transformed message, but any subsequent nodes will not (which makes sense). Generally, it's a good idea to test the existence of a node first, and then test whether it has any content.

for each (obx in msg..OBX)
	if (obx.elements('OBX.1').length() <= 0)
		obx['OBX.1']['OBX.1.1'] = 'empty';
	else if (obx['OBX.1']['OBX.1.1'].toString() == '')
		obx['OBX.1']['OBX.1.1'] = 'empty';
Reply With Quote

fields, obx, repeat, segments, variables

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 01:51 PM.

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