web stats
Filter on XML Data - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-12-2019, 11:58 AM
Iskander Iskander is offline
OBX.2 Kenobi
 
Join Date: Feb 2011
Posts: 55
Iskander is on a distinguished road
Default Filter on XML Data

We have a MC 3.1.1.7461 channel that picks up XML files and distributes them accordingly. I'm trying to filter on data within the XML, but not sure how. For example, we only want to forward when the <DocStatus><StatusType< = "ERROR", otherwise filter it out. I've tried a Rule Builder to 'Accept' when msg['DocStatus']['StatusType'].toString() Equals "ERROR" but it doesn't work. I've also tried this on the Destination filter:


if (msg['DocStatus']['StatusType'].toString() == "ERROR")
{
return false;
}

else
{
return true;
}

But i can't get it to work either. Do i need to somehow map the XML values within the filter, or reference them differently? i have variables mapped on the Source Transformer (Channel Map), which seem to work, given that the variable names AND values show in 'Mappings' in the Dashboard. But when i reference them within the Destination Filter, i get a Reference Error ('...not defined') Is there a way to use variables defined within the Source to filter on the Destinations? or is there a better way filter on data within the XML file?
Thanks much for any help.
Reply With Quote
  #2  
Old 07-13-2019, 04:32 AM
aTom aTom is offline
OBX.3 Kenobi
 
Join Date: Feb 2016
Location: Lake Geneva Area
Posts: 113
aTom is on a distinguished road
Default

Hi

Maybe this is just a copy/paste glitch, but here your code does exactly the opposite as you wish.
__________________
Tom
Reply With Quote
  #3  
Old 07-15-2019, 06:57 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 857
agermano is on a distinguished road
Default

Must come down to missing a small detail. Your Rule Builder step should have worked.

Likewise, channelMap variables added in the source connector should be accessible from your transformer.

Your javascript filter is backwards, as aTom said. You want to return true to accept the message and false to filter it.
Reply With Quote
  #4  
Old 07-17-2019, 04:36 AM
Iskander Iskander is offline
OBX.2 Kenobi
 
Join Date: Feb 2011
Posts: 55
Iskander is on a distinguished road
Default

Thanks for correcting me on the True vs False. I'm still missing something, getting this "TypeError: The content of elements must consist of well-formed character data or markup". The source file looks like normal XML to me. Any thoughts as to what might be wrong?
Reply With Quote
  #5  
Old 07-17-2019, 06:19 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,238
cory_cole is on a distinguished road
Default

Load the data into an XML reader. It will tell you where the error is.
Reply With Quote
  #6  
Old 07-17-2019, 11:05 AM
Iskander Iskander is offline
OBX.2 Kenobi
 
Join Date: Feb 2011
Posts: 55
Iskander is on a distinguished road
Default

The XML file looks fine in an editor. Perhaps i'm missing a basic step somewhere? Here's the error i'm getting:


Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: Test File Reader
CONNECTOR: Destination 1
SCRIPT SOURCE:
SOURCE CODE:
94: }
95: eval('importPackage(' + Packages.java.lang.Class.forName(className).getPac kage().getName() + ')');
96: }
97: }
98: function doScript() {
99: msg = new XML(connectorMessage.getTransformedData());
100: if (msg.namespace('') != undefined) { default xml namespace = msg.namespace(''); } else { default xml namespace = ''; }
101: function filterRule1() {
102: if (msg['DocStatus']['StatusType'].toString() == "ERROR")
103: {
LINE NUMBER: 99
DETAILS: TypeError: The content of elements must consist of well-formed character data or markup.


i'm happy to post the XML if it'd help..
Reply With Quote
  #7  
Old 07-18-2019, 09:12 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 857
agermano is on a distinguished road
Default

Please do attach an original xml file that isn't working (don't copy/paste the text.) That error is occurring before it even reaches the filter you defined. You didn't say you were getting an error. I thought it just wasn't filtering appropriately.
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 01:20 PM.


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