I am trying to eliminate html codes from my data using stripHTML function. I am using the below macro for the same,
'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 < and >
strOutput = Replace(strOutput, "<", "<")
strOutput = Replace(strOutput, ">", ">")
stripHTML = strOutput 'Return the value of strOutput
Set objRegExp = Nothing
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
Any guesses what could be the possible reason for this?
Where did you given this script? In the module side or Somewhere? If module side, what is the usage of this?
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?
I am calling it this way at script side,
Replace(Replace(stripHTML(Remarks), ':', ''), ' ', '') as Remark_PS,
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?
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:
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?
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?
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