|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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';
|
![]() |
| Tags |
| fields, obx, repeat, segments, variables |
| Thread Tools | |
| Display Modes | |
|
|