Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   Convert date regardless of incoming pattern (http://www.mirthcorp.com/community/forums/showthread.php?t=218592)

OmarAQ 09-14-2018 11:27 AM

Convert date regardless of incoming pattern
Hi all;

I am new to Mirth with very little java script knowledge.

I am creating a channel to send an ORM to a PACS server in order to create a MWL, I managed to do so, but there is one problem, I cannot change the date format to: yyyyMMdd.

I searched the forums and found posts talking about this, using the DateUtil.convertDate, but the date I am getting after using it is incorrect (it changes the outcome to yyyyMMdd but not to the correct date).

I think that its because I receive date in multiple formats, mostly as dd-MMM-yy, sometimes as MM/dd/yyyy.

I found below method posted by naruply that changes the format regardless of the inbound message date/time to a specific pattern, no matter what pattern it comes in.


I am stuck here, as I really don`t know what to do with this code, I tried using it in the script section, but I always get: ReferenceError: "convertDate" is not defined.

Would you please help me in this issue.

agermano 09-14-2018 12:37 PM

In the Channels screen, on the left you will see "Edit Code Templates." Go there, and create a new Code Template Library and associate it with any channels that need the function. Then create a new Code Template in your Library and paste "The Code" from the forum post you linked.

After that, you should be able to call convertDate from your transformer.

Download the user guide from the mirth downloads page for more information. It has pictures.

OmarAQ 09-15-2018 01:25 AM

1 Attachment(s)
Thanks agermano, I did exactly as you said, added more date patterns to the list, assigned it to the source connector, and managed to drag and drop it from the user defined functions in my transformer, I am not receiving any errors now, but its removing the date from the outbound message instead of converting it.

My test channel is attached for your kind input.

agermano 09-17-2018 10:58 AM

Try this as your Message Segment.


Your Mapping should probably also be only

but it may work the way you have it.

Edit - I removed the row index after msg['row']. Since you have batch processing enabled on your source connector, you will only ever have one row at a time. If you change your inbound template to only have one row, the drag-and-drop won't include the row index either.

All times are GMT -8. The time now is 02:18 PM.

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