web stats
TypeError: Cannot find function startsWith in object - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-22-2018, 09:43 PM
ppazos ppazos is offline
OBX.2 Kenobi
 
Join Date: May 2008
Posts: 77
ppazos
Default TypeError: Cannot find function startsWith in object

Got this error on a transformer.

The weird thing is message_type_and_version value was get from a toString()

typeof(message_type_and_version) gives string

but startsWith doesn't work https://www.w3schools.com/jsref/jsref_startswith.asp

Ideas?

Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: Test Claims Bridge Prod
CONNECTOR: sourceConnector
SCRIPT SOURCE: TRANSFORMER
SOURCE CODE:
50:
51: var message_type_and_version = msg['ST']['ST.03']['ST.03.1'].toString();
52:
53: logger.info( typeof(message_type_and_version) );
54:
55: if ( message_type_and_version.startsWith("005010X223") )
56: {
57: if ( msg['ST']['ST.03']['ST.03.1'].toString().endsWith("A1"))
58: {
59: logger.info("Inbound 837i is for A1 2007 guide");
LINE NUMBER: 55
DETAILS: TypeError: Cannot find function startsWith in object 005010X222A1.
at 23c5966b-21bb-430d-b0aa-d59975a5ecfd:55 (doTransform)
at 23c5966b-21bb-430d-b0aa-d59975a5ecfd:114 (doScript)
at 23c5966b-21bb-430d-b0aa-d59975a5ecfd:116
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(FutureTask.jav a:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Reply With Quote
  #2  
Old 02-22-2018, 10:05 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,109
agermano is on a distinguished road
Default

String.prototype.startsWith() and .endsWith() are relatively recent additions to javascript, and Rhino (at least the version that ships with mirth) doesn't support them.

You could use java strings...
Code:
var message_type_and_version = new java.lang.String(msg['ST']['ST.03']['ST.03.1'].toString());

logger.info( typeof(message_type_and_version) );

if ( message_type_and_version.startsWith("005010X223") )
{
if ( message_type_and_version.endsWith("A1"))
{
logger.info("Inbound 837i is for A1 2007 guide");
Or a js regex...
Code:
var message_type_and_version = msg['ST']['ST.03']['ST.03.1'].toString();

logger.info( typeof(message_type_and_version) );

if ( message_type_and_version.match(/^005010X223/) )
{
if ( message_type_and_version.match(/A1$/))
{
logger.info("Inbound 837i is for A1 2007 guide");
or any of several other ways to do the same thing.
Reply With Quote
Reply

Tags
javascript

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 08:24 PM.


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