
- 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 02:46 AM
convert start to like
var abc= start.toString(); and then add str.indexOf(abc);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 02:47 AM
Hi Alberto,
This looks like a type case issue.
Add .toString() to str so it becomes
str.toString().indexOf(start);
-Anurag

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 03:18 AM
I did it, now I got the following error:
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: function grabContent(str, start, end) {
7: var startLen = start.length;
==> 8: var s = str.toString().indexOf(start);
9: var e = str.toString().indexOf(end);
10: var scrape = str.substring(s+startLen, e);
11: return scrape;
Do you know how to fix it?
Thanks again 🙂
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 03:26 AM
convert all your function args to string first.
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;
}