web stats
Getting exception using JavaScript replace - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2006, 01:50 PM
nshaik nshaik is offline
Mirth Guru
 
Join Date: Sep 2006
Posts: 302
nshaik
Default Getting exception using JavaScript replace

Message: ADT - A04

Need to remove "-" in patient's SSN ("111-22-3333" should be replaced to "11223333".

Any help in resolving this problem would be greatly appreciated.

Thanks
==============================


Created a transformer JavaScript step called "jsSSN"

******************************************
var originalSSN = msg['PID']['PID.19'].text()[0];
var modifiedSSN = originalSSN.replace(/-/g, "");
localMap.put('patSSN', modifiedSSN);
******************************************

Mirth thorws "Name is not valid" exception when the message is received.

When the "replace" code is commented,
// var modifiedSSN = originalSSN.replace(/-/g, "");
no exceptions are thrown.

The same javascript works fine when I tested on a web page:

========== Test web page ==========
<html>
<body>

<script type="text/javascript">

var originalSSN = "11-22-3333";
var modifiedSSN = originalSSN.replace(/-/g, "");
document.write(modifiedSSN);
</script>
</body>
</html>
==============================

******************** Mirth exception *************
Message : Name is not valid (java.lang.IllegalArgumentException)
Type : org.mule.umo.transformer.TransformerException
Code : 64999
Transformer : Transformer{name='5_destination_1', returnClass=false, returnClass=false, sourceTypes=[]}
JavaDoc : http://mule.codehaus.org/docs/apidoc...Exception.html
************************************************** ******************************
Exception stack is:
1. Name is not valid (java.lang.IllegalArgumentException)
org.apache.xmlbeans.impl.store.Cursor:127 (null)
2. Name is not valid (java.lang.IllegalArgumentException) (org.mule.umo.transformer.TransformerException)
com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer:66 (http://mule.codehaus.org/docs/apidoc...Exception.html)
************************************************** ******************************
Root Exception stack trace:
java.lang.IllegalArgumentException: Name is not valid
at org.apache.xmlbeans.impl.store.Cursor.validateLoca lName(Cursor.java:127)
at org.apache.xmlbeans.impl.store.Cursor._insertEleme ntWithText(Cursor.java:1707)
at org.apache.xmlbeans.impl.store.Cursor._beginElemen t(Cursor.java:1681)
at org.apache.xmlbeans.impl.store.Cursor.beginElement (Cursor.java:4102)
at org.mozilla.javascript.xmlimpl.XML.createTextEleme nt(XML.java:217)
at org.mozilla.javascript.xmlimpl.XML.makeXmlFromStri ng(XML.java:1044)
at org.mozilla.javascript.xmlimpl.XML.putXMLProperty( XML.java:1309)
at org.mozilla.javascript.xmlimpl.XML.replace(XML.jav a:2726)
at org.mozilla.javascript.xmlimpl.XMLObjectImpl.execI dCall(XMLObjectImpl.java:655)
at org.mozilla.javascript.IdFunctionObject.call(IdFun ctionObject.java:124)
at org.mozilla.javascript.optimizer.OptRuntime.call2( OptRuntime.java:74)
at org.mozilla.javascript.gen.c2._c1(<cmd>:7)
at org.mozilla.javascript.gen.c2.call(<cmd>)
at org.mozilla.javascript.optimizer.OptRuntime.callNa me0(OptRuntime.java:106)
at org.mozilla.javascript.gen.c2._c0(<cmd>:8)
at org.mozilla.javascript.gen.c2.call(<cmd>)
at org.mozilla.javascript.ContextFactory.doTopCall(Co ntextFactory.java:337)
at org.mozilla.javascript.ScriptRuntime.doTopCall(Scr iptRuntime.java:2755)
at org.mozilla.javascript.gen.c2.call(<cmd>)
at org.mozilla.javascript.gen.c2.exec(<cmd>)
at org.mozilla.javascript.Context.evaluateString(Cont ext.java:1132)
at com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer.doTransform(JavaScriptTransformer. java:58)
at org.mule.transformers.AbstractTransformer.transfor m(AbstractTransformer.java:197)
at org.mule.impl.MuleEvent.getTransformedMessage(Mule Event.java:251)
at org.mule.providers.jdbc.JdbcMessageDispatcher.doDi spatch(JdbcMessageDispatcher.java:88)
at org.mule.providers.AbstractMessageDispatcher$Worke r.run(AbstractMessageDispatcher.java:257)
at org.mule.impl.work.WorkerContext.run(WorkerContext .java:290)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.runTask(ThreadPoolExecutor. java:650)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.run(ThreadPoolExecutor.java :675)
at java.lang.Thread.run(Unknown Source)

**********************************************
Reply With Quote
  #2  
Old 09-14-2006, 03:41 PM
chrisl chrisl is offline
Mirth Employee
 
Join Date: Aug 2006
Posts: 967
chrisl is an unknown quantity at this point
Default Re: Getting exception using JavaScript replace

Try:

Code:
var originalSSN = msg['PID']['PID.19'].text()[0].toString();
var modifiedSSN = originalSSN.replace(/-/g, "");
localMap.put('patSSN', modifiedSSN);
That should work. You got the first error because originalSSN was pointing to an XML element (the text node of PID.19) and there is no replace method defined on XML text nodes in E4X Javascript.
__________________
Chris Lang
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
TransformerException: Java constructor replace matching JavaScript argument types is ambiguous nshaik Support 7 04-05-2010 08:06 AM
Javascript replace problem. simidau Support 4 01-18-2010 11:25 AM
Javascript to replace an aprostrophe kguru Support 2 02-05-2009 06:30 AM
odd javascript regexp replace behavior skohalmi Support 0 03-19-2008 07:14 AM
javascript parser exception kenth Development 7 11-15-2006 06:51 PM


All times are GMT -8. The time now is 03:25 AM.


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