My js file is below :
var retreivedStorageFile = context.getVariable("storage.file.retrieved");
var val = retreivedStorageFile.replace(/\\/g, " ");
print("retreivedStorageFile is: " + val);
But above code gives :
You have two problems
the error message says "cannot call method "replace" of null. That means the object, on which you are attempting to invoke the .replace() method, is a null value. In your code that is retreivedStorageFile, where you use it on line 2. That object is set in the line above - line 1. Via the context.getVariable() call. Which tells us that the named variable does not exist or holds a null value. It's not set. To protect against this you may want to insert a check for null in your JS code. something like this:
var retrievedFile = context.getVariable('my-variable-name');
if (retrievedFile) {
// do something with it
}
else {
// the context variable is not set
print("context variable is not set.");
// probably here you want to throw an exception?
throw new Error("unexpected: context variable is not set.");
}
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |