web stats
Sending blank vs variable date assignment - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-07-2019, 11:05 AM
Ozz Ozz is offline
OBX.1 Kenobi
 
Join Date: Apr 2015
Posts: 48
Ozz is on a distinguished road
Default Sending blank vs variable date assignment

Hi all,

I am trying to transform this field in either of 2 ways: a variable (converted) or blank. The variable & conversion work when a value is present in that field as anticipated, but when the message errors when the field is BLANK. It's as if my first if/else statement isn't even there. Might I have to make a new variable for when the value is blank, or...?


Code:
var Date1 = DateUtil.convertDate ("yyyyMMddHHmmss", "yyyyMMddHHmm",msg['MSH']['MSH.7']['MSH.7.1'].toString());



  if ( msg['PV1']['PV1.44']['PV1.44.1'].toString() == "" )
       { msg['PV1']['PV1.44']['PV1.44.1'] == "";  }             
               else
               { msg['PV1']['PV1.44']['PV1.44.1'] = Date1;}

Last edited by Ozz; 10-07-2019 at 11:10 AM.
Reply With Quote
  #2  
Old 10-07-2019, 12:10 PM
agermano agermano is online now
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,105
agermano is on a distinguished road
Default

Code:
try {
    var Date1 = DateUtil.convertDate("yyyyMMddHHmmss", "yyyyMMddHHmm", msg['MSH']['MSH.7']['MSH.7.1'].toString());
}
catch(e) {
    Date1 = "";
}
if (msg['PV1']['PV1.44']['PV1.44.1'].toString() != "") {
    msg['PV1']['PV1.44']['PV1.44.1'] = Date1;
}
DateUtil.convertDate will throw an exception if the date you are trying to convert doesn't match the format you specify. By wrapping it in a try/catch, you can handle when the input string isn't in the format yyyyMMddHHmmss.
Reply With Quote
  #3  
Old 10-07-2019, 12:21 PM
Ozz Ozz is offline
OBX.1 Kenobi
 
Join Date: Apr 2015
Posts: 48
Ozz is on a distinguished road
Thumbs up

Quote:
Originally Posted by agermano View Post
Code:
try {
    var Date1 = DateUtil.convertDate("yyyyMMddHHmmss", "yyyyMMddHHmm", msg['MSH']['MSH.7']['MSH.7.1'].toString());
}
catch(e) {
    Date1 = "";
}
if (msg['PV1']['PV1.44']['PV1.44.1'].toString() != "") {
    msg['PV1']['PV1.44']['PV1.44.1'] = Date1;
}
DateUtil.convertDate will throw an exception if the date you are trying to convert doesn't match the format you specify. By wrapping it in a try/catch, you can handle when the input string isn't in the format yyyyMMddHHmmss.


That did it - thank you!

I noticed I included an error in the code I pasted. My full code is much larger, so I pared it down to just the part I was having issues with. I accidentally referenced the MSH segment in the 1st part here, and PV1 in the 2nd. But no matter...your suggestion worked once I applied it properly.

Your explanation of what it was doing confirmed what I had come to realize it was doing to me, but I was not familiar with the try/catch statement. I'll read up on that one so I can learn more. Thanks again.
Reply With Quote
Reply

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 04:59 PM.


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