Link to home
Start Free TrialLog in
Avatar of sidwelle
sidwelleFlag for United States of America

asked on

Mirth: extracting values from the msg (ex4) object w/o thowing errors when the object is not populated.

Looking to write a function to query an ex4 object for a value. My problem is that when I try to extract the value and the field has not been populated, JavaScript throws an error.
I can write a try/catch statement to trap the errors, but when I try to extract many values the code starts to look clumsy.

Is there some way to pass the ex4 object to a function w/o the function throwing an error when passing a ex4.location that has not been populated ?

Example:
var msh7 = msg['MSH']['MSH.7']['MSH.7.1'].toString();    // <- this throws an error if MSH|07 has not been populated. (they didn't send a date)

Why can't I do something like this ?:
var msh7 = getValue(msg['MSH']['MSH.7']['MSH.7.1']);    //  <- but this also throws an error if the location is not populated !?

function getValue(obj){
   try{
      return obj.toString();
   }catch(e){ return '';}   // just return an empty str.
}
ASKER CERTIFIED SOLUTION
Avatar of sidwelle
sidwelle
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial