Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
apoorvasd
Creator II
Creator II

Issue with stripHTML function in QlikView

Hello Everyone,

I am trying to eliminate html codes from my data using stripHTML function. I am using the below macro for the same,

Function stripHTML(strHTML)
'Strips the HTML tags from strHTML

Dim objRegExp, strOutput
Set objRegExp = New Regexp

objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "(?:<style.+?>.+?</style>|<script.+?>.+?</script>|<(?:!|/?[a-zA-Z]+).*?/?>)"

'Replace all HTML tag matches with the empty string
strOutput = objRegExp.Replace(strHTML, "")

'Replace all < and > with &lt; and &gt;
strOutput = Replace(strOutput, "&lt;", "<")
strOutput = Replace(strOutput, "&gt;", ">")

stripHTML = strOutput 'Return the value of strOutput

Set objRegExp = Nothing
End Function

The issue is, when I reload the report locally in my server, the report executes without any errors, but when reloaded on QMC, I get the below error

PR error msg.PNG

Any guesses what could be the possible reason for this? 

Thank you.

10 Replies
Anil_Babu_Samineni

Where did you given this script? In the module side or Somewhere? If module side, what is the usage of this?

Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
jonathandienst
Partner - Champion III
Partner - Champion III

The function looks OK to me (not tested).

Please show the code that invokes the function. Its possible that the function is returning an empty string which is causing another problem.

Do you know which line is throwing the error?

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
apoorvasd
Creator II
Creator II
Author

Hello,

I am calling it this way at script side,

Replace(Replace(stripHTML(Remarks), '&#58', ''), '&#160', '') as Remark_PS,

PR1.PNG

Also just tried to call this expression in a text box to see if I can find any error. Looks like a syntax issue, is it?

Thank you.

 

apoorvasd
Creator II
Creator II
Author

Hello,

Yes, I have written this as a module script. As far as I know it is required to invoke the StripHTML function.

Thank you.

jonathandienst
Partner - Champion III
Partner - Champion III

Have you tested the regex pattern?

It throws errors in a tool like regxr.com for unescaped '/' characters. The error could be coming from the Match() command with a bad pattern. Try:

 

(?:<style.+?>.+?<\/style>|<script.+?>.+?<\/script>|<(?:!|\/?[a-zA-Z]+).*?\/?>)

 

This is valid, but may not be semantically correct.  I suspect you need some more parentheses and the third non capture group is not clear. I assume you want to match the opening and optional closing html tags?

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
apoorvasd
Creator II
Creator II
Author

Hmm...no i haven't tested the regex pattern! Where can I check this?

I tried your new pattern, it isn't working and throwing up the same error!

Any other suggestion?

Thank you.

jonathandienst
Partner - Champion III
Partner - Champion III

regxr.com is one on line tester. There are others

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
apoorvasd
Creator II
Creator II
Author

Okay, will check that. Thank you.

marcus_sommer

Many makros won't be executed on the server-side. There are a few execptions and AFAIK macro-functions belong to them and should work if macros are enabled within the server and the code didn't contain references to the ActiveDocument (didn't exists on this level whereby your code didn't include any) and ActiveX (here I'm not absolutely sure if it's possible - but if ActiveX must be enabled properly within the OS - and I think your used RegEx based on it). If any of the mentioned causes is true it will lead to an invalid function which may return an error-message like yours.

I think I would start with a simple test of a macro-function - maybe with a dummy app/data - which used a single replace() to change e to a. If it's worked you know that such macro-function worked in general and your issue is caused from the ActiveX part. To enable it might be difficult especially as it could violate any security rules in your company.

Your attempt to use the function within the UI won't work unless you enables the macro-functions within the easter egg whereby it's not recommended to change these settings.

As an alternatively you could try to implement your transformation with native Qlik functions. Quite useful for it is mapsubstring(). Here an example what is meant: Passing-parameter-strings-that-contain-special-characters

- Marcus