Can you guys help me out and I apologize if this is a noob question?
I'm trying to iterate over an OBX segment and remove the blank fields.
Here is code that is very similar to my original code but result in the same error:
var obxlength = msg.elements('OBX').length()-1;
for (var i = 0; i <= obxlength; i++) {
msg.OBX[i]['OBX.1']['OBX.1.1'] = i+1;
if (msg.OBX[i]['OBX.5']['OBX.5.1'].toString() == ' ')
delete msg.OBX[i--];
}
Here is the error:
88: var obxlength = msg.elements('OBX').length()-1;
89: for (var i = 0; i <= obxlength; i++) {
90: msg.OBX[i]['OBX.1']['OBX.1.1'] = i+1;
91: if (msg.OBX[i]['OBX.5']['OBX.5.1'].toString() == ' ')
92: delete msg.OBX[i--];
93: }
94: //convert to MDM message type
LINE NUMBER: 90
DETAILS: TypeError: Cannot read property "OBX.1" from undefined
I came across this code from some previous posts:
for (var i = 0; i <= msg.elements('OBX').length()-1; i++) {
msg.OBX[i]['OBX.1']['OBX.1.1'] = i+1;
if (msg.OBX[i]['OBX.5']['OBX.5.1'].toString() == ' ')
delete msg.OBX[i--];
}
This works fine but I need to add some OBX segments at the end so I thought I create a variable for the OBX.length() and place it in the for statement and also use it later.
So I went back to the way I was originally coding it but I continue to get the error and have no idea why. Sorry
Can someone tell me what the difference is?
Shouldn't my obxlength variable should translate to a number and be processed in the loop the same as if I called the method directly in the loop?
Thanks
I'm trying to iterate over an OBX segment and remove the blank fields.
Here is code that is very similar to my original code but result in the same error:
var obxlength = msg.elements('OBX').length()-1;
for (var i = 0; i <= obxlength; i++) {
msg.OBX[i]['OBX.1']['OBX.1.1'] = i+1;
if (msg.OBX[i]['OBX.5']['OBX.5.1'].toString() == ' ')
delete msg.OBX[i--];
}
Here is the error:
88: var obxlength = msg.elements('OBX').length()-1;
89: for (var i = 0; i <= obxlength; i++) {
90: msg.OBX[i]['OBX.1']['OBX.1.1'] = i+1;
91: if (msg.OBX[i]['OBX.5']['OBX.5.1'].toString() == ' ')
92: delete msg.OBX[i--];
93: }
94: //convert to MDM message type
LINE NUMBER: 90
DETAILS: TypeError: Cannot read property "OBX.1" from undefined
I came across this code from some previous posts:
for (var i = 0; i <= msg.elements('OBX').length()-1; i++) {
msg.OBX[i]['OBX.1']['OBX.1.1'] = i+1;
if (msg.OBX[i]['OBX.5']['OBX.5.1'].toString() == ' ')
delete msg.OBX[i--];
}
This works fine but I need to add some OBX segments at the end so I thought I create a variable for the OBX.length() and place it in the for statement and also use it later.
So I went back to the way I was originally coding it but I continue to get the error and have no idea why. Sorry
Can someone tell me what the difference is?
Shouldn't my obxlength variable should translate to a number and be processed in the loop the same as if I called the method directly in the loop?
Thanks
Help with for loop
0 commentaires:
Enregistrer un commentaire