#1
|
|||
|
|||
![]()
I created a channel.
In this source channel (file reader), I get back my XML file which is in a folder. Here is a part of the file : <execute> <date>2019-03-05</date> <heure>11:33:00</heure> </execute> <NABMs>...</NABMs> With a transformer I would like to add this : <prestataire><medecins><medecin><numeroAdeli>12345 </numeroAdeli> <identification><code>AAA</code><libelle>BBB</libelle></identification> </medecin></medecins> <uniteFonctionnelle><code>789</code><libelle>YYY</libelle> </uniteFonctionnelle> </prestataire> between the tag : </execute> and <NABMs> In Destination transformer I create step : type -> Javascript I dont know how to code what I want. ( I never develop on mirth and I know a little about JavaScript) I need help coding my task! Thank you in advance to any one who may be able to give me some ideas. Adrien |
#2
|
|||
|
|||
![]()
I would be happy to assist you in your problem. There are many ways to do what you want. I couldn't possible cover all of them. I will past the code from my message transformer that results in your desired message.
#Note: I had to immediately edit my reply to include the following: I am using Mirth Connect 3.5.2. The notation used to alter the msg body in Mirth Connect is E4X. E4X is a rather old javascript library. This code will not run in a regular javascript engine. Knowing only a little javascript isn't an issue. A larger issue is you are new to E4X and it's syntax. But this will help you. It takes a bit of time to learn the odd bits and catches. #end note I started with an input XML message of Code:
<root> <execute> <date>2019-03-05</date> <heure>11:33:00</heure> </execute> <NABMs>stuff here</NABMs> </root> We can now transform the message in a number of ways. This will add a blank node after the <execute>...</execute> block. please note I use the += operator. This would be equivalent to msg[execute] = msg[execute] + new XML(...); Code:
msg['execute'] += new XML("<prestataire/>"); Code:
var a = <medecins> <medecin> <numeroAdeli>12345</numeroAdeli> </medecin> </medecins>; msg['prestataire']['ValueToBeReplaced'] = a; The following will declare a new XML variable and assign values to child nodes. The child nodes are created during runtime when the values are assigned to them. Then we assign the entire XML node to a location in the message. Code:
var b = new XML('<identification></identification>'); b['code'] = 'AAA'; b['libelle'] = 'BBB'; msg['prestataire']['medecins']['medecin']['numeroAdeli'] += b; Code:
msg['prestataire']['uniteFonctionnelle']['code'] = 789; msg['prestataire']['uniteFonctionnelle']['libelle'] = 'YYY'; The result is the following. Code:
<root> <execute> <date>2019-03-05</date> <heure>11:33:00</heure> </execute> <prestataire> <medecins> <medecin> <numeroAdeli>12345</numeroAdeli> <identification> <code>AAA</code> <libelle>BBB</libelle> </identification> </medecin> </medecins> <uniteFonctionnelle> <code>789</code> <libelle>YYY</libelle> </uniteFonctionnelle> </prestataire> <NABMs>stuff here</NABMs> </root> Take the code blocks one by one and add them to your transformer. Run a test each time and you will see how each block modifies the message. Happy coding! Last edited by collinsmj; 05-22-2019 at 10:18 AM. Reason: added a note |
![]() |
Thread Tools | |
Display Modes | |
|
|