Announcement

Collapse
No announcement yet.

Preprocessor for handling single quotes not functioning

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    I had something similar and used
    Code:
    .replace(/'/g, "''")

    Comment


    • #3
      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, "");

      Comment


      • #4
        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

        Comment


        • #5
          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.

          Comment


          • #6
            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)

            Comment


            • #7
              I used it in a transformer in the source channel

              Comment


              • #8
                single quote

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

                More about....handling single quotes

                Antonio

                Comment

                Working...
                X