
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 02:44 AM
Hi guys,
I have a problem with the below function for parse a string and extract a part of it
function grabContent(str, start, end) {
var startLen = start.length;
var s = str.indexOf(start);
var e = str.indexOf(end);
var scrape = str.substring(s+startLen, e);
return scrape;
}
I got the following error message and I'm not able to have the expected result, could you please help me?
org.mozilla.javascript.EcmaError: Cannot find function indexOf in object [object EmailWrapper].
Caused by error in sysevent_in_email_action.d63f1540c3123100d5907bfaa2d3aebc.script at line 8
6: function grabContent(str, start, end) {
7: var startLen = start.length;
==> 8: var s = str.indexOf(start);
9: var e = str.indexOf(end);
10: var scrape = str.substring(s+startLen, e);
11: return scrape;
Thanks
Alberto
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 03:50 AM
Weird one. toString is native javascript, shouldn't be excluded from scope. Try putting it in the background as Harsh suggested and you could try with the String() function as well:
function grabContent(str, start, end) {
var strString = String(str);
var startString = String(start);
var endString = String(end);
var startLen = startString.length;
var s = strString .indexOf(startString);
var e = strString .indexOf(endString);
var scrape = strString .substring(s+startLen,e);
return scrape;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 03:34 AM
Thanks David, just tried it...same issue:
java.lang.SecurityException: Method returned an object of type IdFunctionObject which is not allowed in scope sn_customerservice
Caused by error in sysevent_in_email_action.d63f1540c3123100d5907bfaa2d3aebc.script at line 8
6:
7: function grabContent(str, start, end) {
==> 8: var strString = str.toString();
9: var startString = start.toString();
10: var endString = end.toString();
11: var startLen = startString.length;
There must be something else but I'm lost at the moment 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 03:36 AM
im beginning to suspect if it is something to do with the scoped app.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 03:43 AM
can you run the same script in background script and select your application scope
and let us know what exactly its returning here.
function grabContent(str, start, end) {
var strString = str.toString();
var startString = start.toString();
var endString = end.toString();
var startLen = startString.length;
var s = strString .indexOf(startString);
var e = strString .indexOf(endString);
var scrape = strString .substring(s+startLen,e);
return scrape;
}
gs.info(grabContent('hey','hello','hi')); // add the parameter value here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 03:50 AM
Weird one. toString is native javascript, shouldn't be excluded from scope. Try putting it in the background as Harsh suggested and you could try with the String() function as well:
function grabContent(str, start, end) {
var strString = String(str);
var startString = String(start);
var endString = String(end);
var startLen = startString.length;
var s = strString .indexOf(startString);
var e = strString .indexOf(endString);
var scrape = strString .substring(s+startLen,e);
return scrape;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 03:53 AM