Can we create a static method in servicenow?

dev115415
Tera Expert
How to create a static method in script include in servicenow?
Let us take a simple example written in JavaScript.
class Car {
  constructor(name) {
    this.name = name;
  }
  static hello() {
    return "Hello!!";
  }
}
 
So how should I write this in ServiceNow?
3 REPLIES 3

Voona Rohila
Kilo Patron
Kilo Patron

Hi @dev115415 

Refer below link https://www.servicenow.com/community/developer-forum/what-are-the-implications-of-creating-a-script-...

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hello @Voona Rohila  I could not understand from that article's example.

Like if I do this 

StaticFunction: function () {

  gs.addInfoMessage("StaticFunction() Called");

  },

so here  StaticFunction is just a name I think like any name.
Could you please help.

so here  StaticFunction is just a name I think like any name - Yes


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP