Demystifying script include: Question 2 - Script include with underscore name?

Anish Reghu
Kilo Sage
Kilo Sage
var GenericIncidentInterface = Class.create();
GenericIncidentInterface.prototype = Object.extendsObject(_ObjectTablesHelper, {
	type: 'GenericIncidentInterface',
	errorValues: 'az.incident.generic.interface.errors',
	logFilter: 'az.incident.generic.interface.logging.functions',

This is part of a code on a interface table for incident.

  • Why do we have the base script include (_ObjectTablesHelper) name starting with underscore(_) ? - Does that make it nay special? I understand that a function starting with an underscore makes it private for any calls from external to the script include. But wondering why have a similar naming convention for script include?

 

Regards,

Anish

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

"I understand that a function starting with an underscore makes it private for any calls from external to the script include".

You will indeed see in a lot more Script Incldues, especially functions within a Script Include starting with an underscore. Though this does not make the function private. It's just a naming convention, nothing more. A naming convention that that function is supposed to be used only within that Script Include. Though you could still call functions like these directly from for example a Business Rule.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

4 REPLIES 4

Mark Roethof
Tera Patron
Tera Patron

Hi there,

"I understand that a function starting with an underscore makes it private for any calls from external to the script include".

You will indeed see in a lot more Script Incldues, especially functions within a Script Include starting with an underscore. Though this does not make the function private. It's just a naming convention, nothing more. A naming convention that that function is supposed to be used only within that Script Include. Though you could still call functions like these directly from for example a Business Rule.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Using the underscore as a prefix of a method is just a best practice to have a visual aid of which methods are intended for internal use within your script include. It's not the same as using private in a class or struct in other programming languages because you can still call the method with underscore outside of the script include.

Mm... good to know.

@Mark Roethof 
Hi Mark,

I had define a function starting with underscore(e.g. _gmmpValue()) in a client callable script Include but it is not working. The function didn't get called from Client script. Please assist on this.

Thanks.

gregouaki
Tera Contributor

Don't forget to call the function with the underscore "_"  before the name of your function and this will work 

Ex : nameOfYourScript()._gmmpValue()

Regards