Set Boundary Script Issue

Hi

I’ve got the below script which I’m getting a error using the split function but I’m confused as to why:

I’ve put a logger in for the value and it’s returning a value so why doesn’t it like this split command?

I am no expert on scripting in Boundaries but wouldn’t you rather the code to do this?

var SecondLine = boundaryValue.split(“|”);

Calling boundaryValue[2] means you are calling the third element of an array. I don’t think it is one at that point yet.

Yeah I thought that, but if I just used boundary value it only extracted the 1st line from the page and this is multiple lines. I found something in the forum which had this in so I tried it.

You can’t see it in the code I have put there but I put a logger in for boundaryValue[2] before the split and thats where the “All 3 --…” you can see in the message pane so I would have thought this is valid

Just tried without the [2] and got

ERROR [28 Sep 2022 19:27:43,957][main] com.objectiflune.datamining.ui.model.RefreshBoundariesJob.run(g.java:-1) Error while refreshing document boundaries: Java class “[Ljava.lang.String;” has no public instance field or method named “split”. (#6) (DME000048)
com.objectiflune.datamining.DocumentManager$DocumentInputException: org.mozilla.javascript.EvaluatorException: Java class “[Ljava.lang.String;” has no public instance field or method named “split”. (#6)
at com.objectiflune.datamining.pdf.data.PDFDocumentManager.findNextDocument(PDFDocumentManager.java)
at com.objectiflune.datamining.pdf.data.PDFDocumentManager.nextBoundaries(PDFDocumentManager.java)
at com.objectiflune.datamining.DocumentManager.refresh(DocumentManager.java)
at com.objectiflune.datamining.PluginInput.refresh(PluginInput.java)
at com.objectiflune.datamining.ui.model.RefreshBoundariesJob.run(RefreshBoundariesJob.java)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.mozilla.javascript.EvaluatorException: Java class “[Ljava.lang.String;” has no public instance field or method named “split”. (#6)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:79)
at com.objectiflune.scripting.engine.OLErrorReporter.runtimeError(OLErrorReporter.java)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1011)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1064)
at org.mozilla.javascript.Context.reportRuntimeError2(Context.java:1034)
at org.mozilla.javascript.NativeJavaArray.get(NativeJavaArray.java:74)
at org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:2320)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2556)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2546)
at org.mozilla.javascript.gen.c_541._c_script_0(:5)
at org.mozilla.javascript.gen.c_541.call()
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:412)
at com.objectiflune.scripting.engine.OLContextFactory.doTopCall(OLContextFactory.java)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3545)
at org.mozilla.javascript.gen.c_541.call()
at org.mozilla.javascript.gen.c_541.exec()
at com.objectiflune.scripting.engine.Script.exec(Script.java)
at com.objectiflune.datamining.scripting.b.run(b.java)
at org.mozilla.javascript.Context.call(Context.java:559)
at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:522)
at com.objectiflune.scripting.engine.OLContextFactory.call(OLContextFactory.java)
at com.objectiflune.datamining.scripting.DataminingScriptEngine.run(DataminingScriptEngine.java)
at com.objectiflune.datamining.pdf.data.PDFSplitOnScriptRule.evaluate(PDFSplitOnScriptRule.java)
at com.objectiflune.datamining.pdf.data.PDFDocumentManager.a(PDFDocumentManager.java)
… 6 more

Turns out the code was fine. It was erroring because one of the pages didn’t have the text on so when it was splitting there weren’t any results. That’s a very strange error I think

Hi @jbeal84,

I assume that you will have to add some checks to your JavaScript code. The following checks, for example:

  1. Check if the boundaryValue array contains at least three strings. You could use the following JavaScript code for this:
var secondLine = []; //boundaryValue[2].split("|");

if (boundaryValue.length >= 3) {
    secondLine = boundaryValue[2].split("|");
}
  1. Check if the secondLine array contains at least two strings. You could use the following JavaScript code for this:
var result = ""; //secondLine[0] + secondLine[2];

if (secondLine.length >= 3) {
    result = secondLine[0] + secondLine[2];
}

P.S. Please note that I’ve changed SecondLine (Pascal Case naming convention) to secondLine (Camel Case naming convention) so that it matches with the rest (of the applied naming convention).


The following error message does occur because boundaryValue[2] is undefined and, as the error message stated, you cannot call method split of undefined. You can check this by executing the JavaScript code logger.info(typeof boundaryValue[2]); and check the result in the Messages pane.

Error while refreshing document boundaries: TypeError: Cannot call method "split" of undefined (#2) (DME000048)

The following error message does occur because you cannot execute the split method following an array.

Error while refreshing document boundaries: Java class "[Ljava.lang.String;" has no public instance field or method named "split". (#3) (DME000048)

To solve this you will just have to do the same thing as you were already doing, which is: Execute the split method following a string, like for example:

secondLine = boundaryValue[2].split("|");

Perfect thanks Marten

1 Like

Hi @jbeal84,

You’re welcome.

I see that I made a small mistake in the second JavaScript code example which I’ve shared by my previous comment and which I’ve updated. For your interest: The condition applied to the if-statement has been changed from secondLine.length >= 2 to secondLine.length >= 3.