

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hello all,
I have a question that I am sure will be easy for many people, just not me...
I am reading and storing a long string into a trigger I setup on a table, and I need the first part of it only. How can I get that either directly in the trigger, or by calling a Script? I've tried the .before and .after functions that I saw in other places, but couldn't get them to work here.
Example string is
IM123456 The server is down US_Server Support 09:12:25
I can't figure out how to get just the IM123456 out of the first part of the string. There are no spaces in front of the IM#, so I just need to know how to read up until the first space.
Thanks ahead of time!
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I'm not too familiar with the before function. You could try this. Copy from 1st character to the position of first space.
im = thename.substr(0,str.indexOf(' '));


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I'll add what I have as of now.
thename is equal to "IM123456 The server is down US_Server Support 09:12:25" from my example
function getIMNumber( thename )
{
if ( thename )
{
var im=thename;
print("IM before function: ", im);
im = im.before(" ");
print("IM after function: ", im);
return im;
}
else
return false;
}
The error I am seeing in the sm.log is
1720( 2828) 07/01/2014 12:36:13 RAD E Script 'GetIMNumber' line 7: ERROR TypeError: im.before is not a function at char 1

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I'm not too familiar with the before function. You could try this. Copy from 1st character to the position of first space.
im = thename.substr(0,str.indexOf(' '));


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.
Example
Extract parts of a string:
var res = str.substr(1, 4)
The result of res will be:


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Thanks for the help, I got it to work. A slight tweak was needed, but the end working function for others to see is this.
function getIMNumber( thename ) { if ( thename ) { var im; print("IM before function: ", im); im = thename.substr(0,thename.indexOf(" ")); print("IM after function: ", im); return im; } else return false; }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content