In Connect 2021.2, writing a Boundary Script, I need to trim a scraped region/value. But I’m getting errors that “trim()” isn’t a function.I also tried “replace()” with a RegEx, which also fails.
Why doesn’t the Boundary API have access to Javascript string functions?
EDIT: This is a PDF job, with an account number on the top of most pages. If it isn’t there, that area will be blank and the page is part of the current record. So the task of the Boundary Script is to scrape the account number, and if it’s not blank/null, compare it to the account number saved into a boundary variable from the previous page/scraped region. If the number is not null, and doesn’t equal the boundary variable, time to set a boundary.
The problem is my two strings, even if equal, were evaluating as not equal. I suspected that I was picking up spaces or extraneous characters, so thought to trim() them both. That fails. I tried casting to INT via parseInt(), since the Account Number is numeric. The cast failed, giving me “NaN”, which confirmed that I was picking up space or junk characters.
I added vocaJS as an external library and used their v.trim() function, and that resolved the issue.
We really need access to string functions in Boundary Scripts!!
//read the Account Number into a JS variable zeAccount
var zeAccount = boundaries.get(region.createRegion(24.5,3.0,47.0,12.0));
var storedAcct = boundaries.getVariable("AcctNum");
//check to see if we've already processed a boundary and stored the account number into the "AcctNum" boundary variable
//if not, it will be null and we're on record one
if(storedAcct !=null)
{ //we're here which means AcctNum exists and holds a value, so we are mid-record, possibly the start of a new record
//we need to set a new document boundary IF the value we just scraped into "zeAccount" doesn't match the last value we scraped & stored,
//AND the value we just scraped isn't null/blank
if( (v.trim(zeAccount[0]) != v.trim(storedAcct)) && (zeAccount[0] != null) )
{
//set the new document boundary
boundaries.set();
}
}
//store the value we scraped into a boundary variable, unless it was null
//if it WAS null, we are on a blank page and don’t want to store a “false positive” null value as a document boundary
if(zeAccount[0] != null)
{
boundaries.setVariable("AcctNum",zeAccount[0]);
}