Split function not working in script

Aps3
Kilo Contributor

Hello Team,

I tried putting logs and got an error message 'Split function not working'

"org.mozilla.javascript.EcmaError: Cannot find function split in object ".

Script:

answer = [];
SwissTriggerApproval();
function SwissTriggerApproval()
{
var affCIs = new GlideRecord('task_ci');
gs.log('Hello ' +affCIs);
affCIs.addQuery('task', current.sys_id);
affCIs.query();
while(affCIs.next())
{
//answer.push(affCIs.ci_item.u_task);
var list = current.u_watch_list_group;
gs.log('Hello1 ' +list);
var array = list.split(",");
for (var i=0; i < array.length; i++)
{
answer.push(array[i]);
gs.log('Hello2 ' +array[i]);
}
}
}

Error1:

org.mozilla.javascript.EcmaError: Cannot find function split in object .

Caused by error in sys_ui_action.f07eedb3cb200200d71cb9c0c24c9c3d.script at line 14

11: //answer.push(affCIs.ci_item.u_task);
12: var list = current.u_watch_list_group;
13: gs.log('Hello1 ' +list);
==> 14: var array = list.split(",");
15: for (var i=0; i < array.length; i++)
16: {
17: answer.push(array[i]);

Error 2:

org.mozilla.javascript.EcmaError: Cannot find function split in object .
Caused by error in sys_ui_action.f07eedb3cb200200d71cb9c0c24c9c3d.script at line 17

14: var array = list.split(",");
15: for (var i=0; i < array.length; i++)
16: {
==> 17: answer.push(array[i]);
18: gs.log('Hello2 ' +array[i]);
19: }
20: }

org.mozilla.javascript.EcmaError: Cannot find function split in object .
Caused by error in sys_ui_action.f07eedb3cb200200d71cb9c0c24c9c3d.script at line 17

14: var array = list.split(",");
15: for (var i=0; i < array.length; i++)
16: {
==> 17: answer.push(array[i]);
18: gs.log('Hello2 ' +array[i]);
19: }
20: }

 

PLease provide some inputs so that it can be resolved.

Thanks

9 REPLIES 9

Hello Anirudh,

Thanks for the reply but no luck.

Could you please provide the exact code.

May be I am missing something.

Thanks

Aman Singh_
Kilo Sage

Hi,

 

Use and check once.

var array = list.toString().split(','); 

Please mark reply as Helpful/Correct, if applicable. Thanks!

Aman

Aps3
Kilo Contributor

Hello Aman,

No luck.

Thanks

Maik Skoddow
Tera Patron
Tera Patron

Hi

which type is the custom field "u_watch_list_group"?

I assume it is a reference field. If so you cannot split that field as basically there is only a sys_id stored in it.

Kind regards
Maik

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

shahebaz4
Tera Contributor

Hello,

Please check this KB Article

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1275119

Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!