Help with Script "slice()"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 06:39 AM
Script:
```
var gm= new GlideRecord("sys_user_grmember");
gm.addQuery("group","220f8e71c61122840197e57c33464f70");
gm.query();
var list='';
while(gm.next())
list += gm.user.toString() + " , " ;
list = list.slice(0, - 1);
gs.log(list);
```
Prints the trailing comma as well, even though I have got slice().
But below script removes the last charactor:
```
var abc = "123456789";
abc = abc.slice(0, - 1);
gs.log(abc);
```
Prints: 12345678
Can someone advise why first script is not removing the last comma?
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 11:51 AM
Hello Sunita,
Try with the updated code below and let me know.
var gm= new GlideRecord("sys_user_grmember");
gm.addQuery("group","220f8e71c61122840197e57c33464f70");
gm.query();
var list='';
if(gm.next()) {
list += gm.user.toString() ;
}
while(gm.next())
list += "," +gm.user.toString() ;
gs.log(list);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2017 03:26 AM
Thanks.
I know that will work, I have it working. Basic logic.
Question was: in my code, why slice() is not working for case#1.
Any Thoughts?