com.glide.script.RhinoEcmaError: Cannot find function indexOf in object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I am getting the below error for the code:
com.glide.script.RhinoEcmaError: Cannot find function indexOf in object .
Access Control: '<custom_table_name>' : Line(3) column(0)
1: var userId = gs.getUserID();
2:
==> 3: current.watch_list.indexOf(userId) > -1 ||
4: current.u_key_user_watch_list.indexOf(userId) > -1
5: ;
Any idea how to deal with this error? I am very new to coding side of things so looking for anyone who can help me here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
variable watch_list can be empty. then it cann't use indexOf directly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Helllo @kartikchoum ,
Please give it a try to the code below and see & let me know how it works for you,
var userId = gs.getUserID();
var wl = current.watch_list.toString().split(',');
var keyWl = current.u_key_user_watch_list.toString().split(',');
(wl.indexOf(userId) > -1) || (keyWl.indexOf(userId) > -1);
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
see if watch_list is empty.
If yes then script will fail.
Also use toString() and then use indexOf()
current.watch_list.toString().indexOf(userId) > -1 ||
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader