web stats
Non working code, please help>> element = element.replace(/&/g, '\\T\\'); - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 05-28-2018, 09:12 PM
lavanian lavanian is offline
What's HL7?
Join Date: Mar 2012
Posts: 1
lavanian is on a distinguished road
Send a message via Skype™ to lavanian
Default Non working code, please help>> element = element.replace(/&/g, '\\T\\');

I use Mirth 3.5.2 on a windows 10 machine and am trying to replace the &,~^| etc with their escape characters by using the syntax "chr.replace(xx,yy)". I have tried at least 4 or 5 different code snippets, some from this forum, but Every one of them get stuck at the actual syntax with the error "The choice of Java method java.lang.String.replace matching JavaScript argument types (function,string) is ambiguous;"
I have pasted the error code below. Thanks in advance for the help.

Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: escapeChrsUse
CONNECTOR: sourceConnector
74: try{
75: // if it's an xml branch, serialize it
76: element = SerializerFactory.getSerializer('HL7V2').fromXML(e lement);
77: } catch(err){
78: // if it's plain value, unquote it
79: element = element.replace(/&/g, '\\T\\');
80: }
81: // return the raw value
82: return element;
83: }
DETAILS: The choice of Java method java.lang.String.replace matching JavaScript argument types (function,string) is ambiguous; candidate methods are:
class java.lang.String replace(char,char)
class java.lang.String replace(java.lang.CharSequence,java.lang.CharSeque nce)
at 3d350da3-438f-4ddd-9529-f31bb46b6c46:79 (getRawValue)
at 3d350da3-438f-4ddd-9529-f31bb46b6c46:85 (doTransform)
at 3d350da3-438f-4ddd-9529-f31bb46b6c46:109 (doScript)
at 3d350da3-438f-4ddd-9529-f31bb46b6c46:111
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:154)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:119)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)
Reply With Quote
Old 05-29-2018, 06:55 AM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road

The serializer returns a Java string, but you are trying to do a Javascript replace on it.

This will convert element and the result to a javascript string.
element = String(element).replace(/&/g, '\\T\\');
This will use the Java replace function and return a Java string.
element = element.replaceAll('&', '\\T\\');
Though, there is a good change that when you serialize it, you'll get an actual & character instead of &
Reply With Quote

control characters, escape characters, replace

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 03:21 PM.

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