Skip to main content

I have the following inline js resource, which worked fine in Brooklyn but now is throwing an error in spark. The error is “There was a problem rendering a component of type skuidpage: Cannot read property ‘split’ of null”. The error is being thrown on the line bolded in the code below.

What’s the solution, here?

//Custom Formulas//
(function (skuid){

//Shortcuts & Global Variables//
var $ = skuid.$;

//Formulas//
var formulas = {
‘REMOVE_TEXT’: M
function (string_to_search, string_to_remove) {
return string_to_search.split(string_to_remove).join(‘’);
},
{numArgs: 2, returnType: ‘text’}
]
};

//Register Formulas//
$.each(formulas,function(name,formulaArray){ skuid.formula.Formula(name, formulaArrayu0], formulaArrayA1]); });

})(skuid);```

I’m guessing that in Spark the formula is now being executed in a situation where previously it was not, in which the input to the formula is not defined, e.g. a field value on a row is undefined or empty. But honestly I’m surprised you haven’t gotten hit with this same error until now, as your formula isn’t defending itself against bad inputs — a simple fix would be to check that string_to_search is defined before attempting to split on it, i.e. change the part in bold to this:

return string_to_search && string_to_search.split(string_to_remove).join(‘’);

This will prevent your formula from attempting to call “split” unless you’ve actually got an input value.


Right! Thanks. I’m ashamed I didn’t just fix that myself…


Reply