-
Type: Bug
-
Status: Resolved
-
Priority: Minor
-
Resolution: Fixed
-
Affects Version/s: 10.10
-
Component/s: Automation
-
Tags:
-
Backlog priority:600
-
Upgrade notes:
-
Sprint:nxplatform 11.1.15, nxplatform 11.1.16
-
Story Points:2
PlatformFunction Fn.htmlEscape not available in JS automation
Reproduce:
- Create a JS Automation script
- Set it to:
function run(input, params) { var html = "<html><body>Coucou</body></html>"; // Use type ahead => this function is supposed to be available var escaped = Fn.htmlEscape(html); Console.log(escaped); }
- Run it (easy way: have JSF, create an Automation Action for Admin in the User Menu. Doing equivalent in Designer takes only one more minute to display a button anywhere)
Result is Java stack error with:
Caused by: jdk.nashorn.internal.runtime.ECMAException: TypeError: Fn.htmlEscape is not a function
While it is a PLatforFunction, see here (this is master but it exists in 10.10 of course).
Work arounds can be:
- Use escape() JS API if it's enough for you, but it's "almost" deprecated
- Wrapp the call in a regular automation chain. Very cumbersome:
wrapper_htmlEscape Automation Chain. Here is its YAML:
description: "Calling Fn.htmlEscape in JS fails with:\nCaused by: jdk.nashorn.internal.runtime.ECMAException: TypeError: Fn.htmlEscape is not a function\n\nCaller has set the htmlToEscape Context variable to the HTML" operations: - Context.SetVar: name: escapedHtml value: "@{Fn.htmlEscape(htmlToEscape)}"
Your script becomes:
function run(input, params) { var html = "<html><body>Coucou</body></html>"; // Use type ahead => this function is supposed to be available //var escaped = Fn.htmlEscape(html); // ======================================================== // Create a Context Var with the HTML string ctx.htmlToEscape = JSON.stringify(bodyJSON); // WARNING: wrapper_htmlEscape uses this variable. If you change its name, change wrapper_htmlEscape RunOperation(null, {'id': "wrapper_htmlEscape"}); // wrapper_htmlEscape returns the escaped HTML in the escapedHtml Context var escaped = ctx.escapedHtml; Console.log(escaped); }
Another workaround: Use org.nuxeo.ecm.automation.features.PlatformFunctions.htmlEscape (see comment below)