web stats
Change field value not working - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2012, 05: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)
cells.push(obx['OBX.1']['OBX.1.1'].toString());
else {
//obx['OBX.1']['OBX.1.1'] = "empty";
//cells.push(obx['OBX.1']['OBX.1.1']);
//cells.push(msg['OBX']['OBX.1']['OBX.1.1']);
//cells.push(obx['OBX.1']['OBX.1.1'].toString());
//cells.push(msg['OBX'][rowSize]['OBX.1']['OBX.1.1']);
cells.push("empty");
}
}
logger.error(cells[cellCount].name +", "+ cells[cellCount].value);
cellCount++;
Thanks for any help.
Reply With Quote
  #2  
Old 04-13-2012, 05:59 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 4,063
narupley is on a distinguished road
Default

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.

Code:
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
Reply

Tags
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 -7. The time now is 12:34 PM.


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