web stats
Preprocessor for handling single quotes not functioning - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2015, 10:39 AM
mirthguy301 mirthguy301 is offline
Mirth Newb
 
Join Date: Sep 2015
Posts: 14
mirthguy301 is on a distinguished road
Default Preprocessor for handling single quotes not functioning

Hi all, I am fairly new to Mirth but not JavaScript or SQL. I was wondering if anyone could shed some insight as to why an incoming message might not be handled by the preprocessor or why the preprocessor is not firing.

There seems to be an error when the message comes in with a single quote, EmployerName: APPLEBEE'S. I have tried
Code:
message = message.replace(/\'\'/g, ""); return message;
and
Code:
return message.replace(/\'\'/g, "");
With no luck. The error seems to be that it gets passed the preprocessor and tries to write to the database but errors out because SQL doesn't like that single quote in the data without the companion quote.

Does anyone have any insight to this? I've tried a few variations that are on this forum but they seem to be a bit outdated because the syntax errors out . I even tried to replace in the data writer but it didn't seem to help either.
Reply With Quote
  #2  
Old 09-29-2015, 11:33 AM
dac1005 dac1005 is offline
Mirth Newb
 
Join Date: Jun 2015
Location: Mobile, AL
Posts: 12
dac1005 is on a distinguished road
Default

I had something similar and used
Code:
.replace(/'/g, "''")
Reply With Quote
  #3  
Old 09-29-2015, 12:35 PM
plew plew is offline
OBX.1 Kenobi
 
Join Date: Oct 2011
Posts: 34
plew is on a distinguished road
Default

Quote:
Originally Posted by mirthguy301 View Post
Code:
message = message.replace(/\'\'/g, ""); return message;
Code:
return message.replace(/\'\'/g, "");
Your example has one single-quote, but your regular expression is looking for two. Dac is on the right track, but their example is doubling all single-quotes. If you want all single quotes removed, do this instead:
Code:
return message.replace(/'/g, "");
Reply With Quote
  #4  
Old 09-29-2015, 02:12 PM
mirthguy301 mirthguy301 is offline
Mirth Newb
 
Join Date: Sep 2015
Posts: 14
mirthguy301 is on a distinguished road
Default

Quote:
Originally Posted by plew View Post
Your example has one single-quote, but your regular expression is looking for two. Dac is on the right track, but their example is doubling all single-quotes. If you want all single quotes removed, do this instead:
Code:
return message.replace(/'/g, "");
So if this was the case that makes sense why the preprocessor wasn't doing anything I noticed. I added this logic to the actual data writer and it worked:
Code:
var GuarantorEmployerName = msg['GT1']['GT1.16']['GT1.16.1'].toString().replace(/'/g,"''");
But I will add what you have back to the preprocessor
Reply With Quote
  #5  
Old 09-30-2015, 05:49 AM
dac1005 dac1005 is offline
Mirth Newb
 
Join Date: Jun 2015
Location: Mobile, AL
Posts: 12
dac1005 is on a distinguished road
Default

If you want to remove the single quote from the word, use Plew's solution, but if you want it to stay in, try mine.
Reply With Quote
  #6  
Old 09-30-2015, 06:26 AM
mirthguy301 mirthguy301 is offline
Mirth Newb
 
Join Date: Sep 2015
Posts: 14
mirthguy301 is on a distinguished road
Default

Quote:
Originally Posted by dac1005 View Post
If you want to remove the single quote from the word, use Plew's solution, but if you want it to stay in, try mine.
You used that in the preprocessor? That code you posted is what I put in the Data writer (my most recent post)
Reply With Quote
  #7  
Old 10-01-2015, 05:40 AM
dac1005 dac1005 is offline
Mirth Newb
 
Join Date: Jun 2015
Location: Mobile, AL
Posts: 12
dac1005 is on a distinguished road
Default

I used it in a transformer in the source channel
Reply With Quote
  #8  
Old 05-03-2016, 11:36 PM
antoniosarco antoniosarco is offline
What's HL7?
 
Join Date: May 2016
Posts: 1
antoniosarco is on a distinguished road
Default single quote

generally when u deal with apostrophe
u replace the the single quote(')
with ('').

More about....handling single quotes

Antonio
Reply With Quote
Reply

Tags
hl7, preprocessor, quotes, single quotes

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:52 PM.


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