com.glide.script.RhinoEcmaError: Cannot find function indexOf in object

kartikchoum
Tera Contributor

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.

3 REPLIES 3

JackieZhang
Tera Contributor

variable watch_list can be empty.   then it cann't use indexOf directly. 

Aniket Chavan
Tera Sage
Tera Sage

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

Ankur Bawiskar
Tera Patron
Tera Patron

@kartikchoum 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader