NetTalk Central

Author Topic: How to remove invalid chars from Alert Message?  (Read 3204 times)

Neil Porter

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
How to remove invalid chars from Alert Message?
« on: February 13, 2013, 05:46:10 AM »
I'm using a 3rd party soap server to communicate with one of my own NT webservers. I capture information using a Netweb form, send the data to the 3rd party and look for some return data.

Depending on the data passed, I sometime get some sort of error message back from the 3rd party.

I want to pass on this error to my NT webserver user.

What I've found is that there are some characters in the response message that cause the NT alert message not to display. If I capture the message in a stop box, it looks fine. I've been playing with String Theory to see if there are some characters included in the response that is causing my problem. I tried to use the URLencode command, and this showed that I had %0D%0A at the end of my response. If I removed those characters and re-encoded the message, it displayed fine.

Unfortunately there seem to be other examples (see attached screen shot)

Does anyone know of a function that I can use to strip out any potentially invalid characters?

Regards,

Neil.

[attachment deleted by admin]
Clarion 11.0.13244
NetTalk 11.04

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: How to remove invalid chars from Alert Message?
« Reply #1 on: February 13, 2013, 10:43:29 PM »
Hi Niel,

I think you want to perhaps spell out the exact flow of the text in a little more detail. It's definitely possible to encode, and decode, at the various places, but the exact path of the text is critical to determining what needs to be done where.

the Stop that you displayed in the image is "url encoded". This can be decoded using the _UnEscape method.
ie

stop(p_web._Unescape(whatever))

chances are though you don't want it to "stop" here - you want to push it to the browser. Exactly the best way of doing that depends a lot on the context - ie what the user is doing to trigger the process in the first place.

the most likely thing you'll need to do is

p_web.SetAlert(p_web._Unescape(whatever))

Cheers
Bruce

Neil Porter

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: How to remove invalid chars from Alert Message?
« Reply #2 on: February 14, 2013, 08:54:40 AM »
Hi Bruce,

You are right, I am trying to do a little more with the response:

I've added this following to my Validate All - 2 End embed point on a netweb form:

! Write to 3rd Party Carrier
IF LOC:Invalid <> '' Then Exit.

DO WriteTPNLive
IF p_web.gsv('TPNErrorMessage') <> ''
  loc:InvalidTab = 1
  loc:Invalid = 'JOB:JobReference'
  JOB:JobReference:IsInvalid = TRUE
  LOC:TPNErrorMessage = p_web.gsv('TPNErrorMessage')
  ST.SetValue(LOC:TPNErrorMessage)
  ST.UrlEncode()
  STOP(CLIP(ST.GetValue()))
  !ST.Replace('%0D%0A','+')
  !ST.UrlDecode()
  LOC:Alert = CLIP(p_web._UnEscape(ST.GetValue()))
  STOP(LOC:Alert)
  p_web.SetAlert(p_web._Unescape(ST.GetValue()))
END

For normally formatted reponses (ie. ones without hidden characters) this seems to work fine. I call Do WriteTPNLive, and this either sets some values in my DB, or Sets the TPNErrorMEssage, which I want to display to the end user. If I trap the error message that comes back from the 3rd party server, it looks fine, but when I assign it to LOC:Alert I don't get a popup warning box, like I do with all of my other validation. When I check the source of the page that has been generated, I see the following:


<div id="_busy" class="nt-busy" data-nt-busy="busy"><img src="/images/_busy.gif" /></div><div id="_ver651" class="nt-alert ui-state-error ui-corner-all">Error in site JavaScript</div><script>versionCheck('6.51');getScreenSize()</script>

 If I manually set LOC:Alert to be 'Hello World' it works as expected.

So I deduced that there must be some hidden chars in the error message that I couldn't see in a stop message, that affected the java script. Hence I tried using URLEncode just to display any invisible characters to me.If I then put code in place to replace the non visible characters and decode it again, the message displays.

The problem is that there are all sorts of variable messages that come back from the 3rd party, and I don't know what all of the possible characters are that I need to replace.

I need to find some way of stripping out any non visible characters.

Your suggestion of using _unescape unfortunately doesn't seem to work in this instance.

I was wondering if I should do a brute force loop through each character in the error message checking it's CHR value, and replacing the it if it fell outside of a specific range, but I'm not sure what that range might be, as I'm not really sure what it is exactly that is screwing up the java.

Does that sound reasonable?

Regards,

Neil.
Clarion 11.0.13244
NetTalk 11.04

Neil Porter

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: How to remove invalid chars from Alert Message?
« Reply #3 on: February 14, 2013, 09:30:32 AM »
You know how sometimes, just writing something down in here, gives you an idea......

I've done what I said, and written a little function that loops through each character im my message, and replaces any VAL() less than 32 and greater than 126 with a space, and it works like a charm.

Thanks for your input anyway Bruce!
Clarion 11.0.13244
NetTalk 11.04