Extension - Javascript

I currently have a little script running that reads a value and if it contains “Lansing” or “Midland” outputs “Lansing”, else it outputs “”. great.

var result = “ARG1”;
if (result.includes(“Lansing”) || result.includes(“Midland”))
{
result = “Lansing”;
}
else
{
result = “”;
}
result = result;

It runs perfect on the assembly editor.

When i run it in the automation, I get the error

javax.script.ScriptException: TypeError: result.includes is not a function in at line number 2.

not sure the issue since it works in the assembly editor

When JavaScript is run in the assembly editor it is executed in the browser, when it runs in an automation it runs in the Java interpreter.

The error means the includes() method is not available when running in the script in Java.

The Java Nashorn engine in Java 8 does not implement the latest ECMAScript version.

ok. so what would be the proper call? indexOf?

Yep, use indexOf() to find a substring.

1 Like