String.split(" ") not working

jasonthorngren
Giga Contributor

Trying:

 

var regexp = /Status:(.*)/g;
if (str.match(regexp)) {
str = str.match(regexp);
gs.log('*** ISSUE: strRegEx = ' + str); 
var status = str.split(" ");
gs.log('*** ISSUE: Status = ' + status[1]);

Getting: 


Information	*** ISSUE: strRegEx = Status: Done (was: Testing)

Warning          org.mozilla.javascript.EcmaError: Cannot read property "1" from undefined
Caused by error in sysevent_script_action.95636cdbdba1181072bea04913961902.script at line 10

7: str = str.match(regexp);
8: gs.log('*** ISSUE: strRegEx = ' + str);
9: var status = str.split(" ");
==> 10: gs.log('*** ISSUE: Status = ' + status[1]);

Information	*** ISSUE: Status = undefined
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

It looks like it's not able to split str, so forcing str to a string should do it

str = str.match(regexp).toString();

View solution in original post

6 REPLIES 6

Kunal Varkhede
Tera Guru

Hi,

 

var regexp = /Status:(.*)/g;

str = str.match(regexp);

gs.log('*** ISSUE: strRegEx = ' + str);

var status = str.split(" ");

gs.log('*** ISSUE: Status = ' + status); //try like this check what happend

 

Thanks,

Kunal

Jaspal Singh
Mega Patron
Mega Patron

Hi Jason,

 

If I understand correctly this is not the complete code. Can you share the complete code once.

Brad Bowman
Kilo Patron
Kilo Patron

It looks like it's not able to split str, so forcing str to a string should do it

str = str.match(regexp).toString();

Yes!  Thank you!! After I thought about it make sense why it was saying it was undefined and it needed to be defined as string.

Thank you Brad!  Thank you ServiceNow community so helpful!!