Why can't I use Set() data structure in server script?

rushinarwade1
Tera Contributor

Hi there,
I am trying to use Set() data structure in widget server script but I am getting below error when I am loading the page.
Can you please tell me how can I use Set data structure in server script?
I have heard about Mozilla JS extension (moz) but I don't know how to use that, even if it application in this case.

Please guide me!

Code line: 

 

var reqSet = new Set();

 

 

Error:

rushinarwade1_0-1693309448851.png

 

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I believe Set() is an ES6 function, so you'd need to make sure you have Javascript mode set to ECMASCript 2021 on the app you're working in. Here's an article with steps on how to do that and then which methods are supported once you turn it on: https://developer.servicenow.com/blog.do?p=/post/tokyo-ecmascript-2021

View solution in original post

2 REPLIES 2

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I believe Set() is an ES6 function, so you'd need to make sure you have Javascript mode set to ECMASCript 2021 on the app you're working in. Here's an article with steps on how to do that and then which methods are supported once you turn it on: https://developer.servicenow.com/blog.do?p=/post/tokyo-ecmascript-2021

Thanks for your reply Brad. I am totally satisfied with your answer!