Does anyone know anything about this lastIndexOf function? I'm trying to extract the last level in the generatedcats field in the kmdocument table. The data looks something like this:
Infrastructure SOPs > Data Center ... or ...
Infrastructure SOPs > End User Svc > NHD
I only want the last level, no matter how many levels it is. Looking thru the Java Script Basics book, I found the function lastIndexOf(). According to the book (and several sites), it indexes for the last occurrence of whatever character you provide.
When I try to use it, I get the following error:
Script 'KMGenCatsStripper' line 6: ERROR TypeError: $gencats.lastIndexOf is not a function at char 1
Here is my code:
=====================================
function KMLastLevelCat(record)
{
var $gencats = record.generatedcats;
print($gencats);
var $pos = $gencats.lastIndexOf(">"); <<< this is line 6
print($pos);
if ($pos >=0)
{
$end = $gencats.length;
$lastcat = $gencats.substring($pos, $end);
}
else $lastcat = $gencats;
print($lastcat);
return $lastcat;
=============================
I'm calling it just from a display option, and right now, only having it print to screen, so I can see that it works.
Can anyone help with this? I admit, I'm very new at this javascript stuff. Are there certain functions that arent available to SM (and if so, why's it in the Mike Sanders book)?
Any help would be greatly appreciated.


Reply With Quote
Bookmarks