How To write simple JavaScript in Servicenow

StacyLen
Mega Guru

I am embarrassed to ask this question.   

I am on lesson 15 of Chuck Tomasi Learn JavaScript on the Now Platform.   Trying to work Lab 4.   I have a PDI.  

My problem is that I don't know what Navigator App or Module to select in order to start writing the simple JavaScript such as the below:

 

Any help appreciated

 

// Lab 4:
// Create a script that takes a string variable "Hello world"
// and translates it to at least 3 different languages
// based on a 'language' variable.
// Make the default language English if a match isn't found.

var language = 'German';
var fromString = 'Hello world';
var toString = '';

switch (language) {
case 'German':
toString = 'Hallo Welt';
break;
case 'French':
toString = 'Bonjour le monde';
break;
case 'Spanish':
toString = 'Hola Mundo';
break;
default:
toString = 'Hello, world';
}

gs.info(fromString + ' in ' + language + ' ==> ' + toString);

 

StacyLen

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron

Hi StacyLen,

You can run this using 'Fix Scripts' or 'Scripts - Background' in the left nav.  Other examples in this video series will use Business Rules, Script Includes, Client Scripts, or scripted REST API.  He will direct you in the videos when to use each of these.

View solution in original post

7 REPLIES 7

nayanmule
Kilo Sage

@StacyLen  , you can use the background scripts or fix scripts to test your code.

nayanmule_0-1766991125546.png

 

Regards,

Nayan

Anand Kumar P
Tera Patron

Hi @StacyLen ,

 

Open ‘Scripts - Background’ from left navigation and paste your script and click on Run Script button to execute and see output.

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

BillMartin
Giga Sage

Hi @StacyLen ,

 

No need to be embarrassed at all. This is actually one of the most common points of confusion when people are new to JavaScript on the Now Platform.

 

For simple JavaScript exercises like Lab 4, you do not need a specific application or module. You should use:

Navigator → System Definition → Scripts – Background

Scripts – Background is the safest place to practice and run pure JavaScript logic like variables, switch statements, and string handling. You can paste your code there, run it, and see the output immediately.

 

A couple of important clarifications that often help:

 

  • You are not “missing” a module. Labs like this are about JavaScript thinking, not building ServiceNow records.

  • gs.info() (or gs.print()) is only there to display output. The JavaScript itself is platform-neutral.

  • You are learning logic flow (switch, variables, defaults), not ServiceNow APIs at this stage.

 

Your example code is perfectly valid for running in Scripts – Background, and it will work exactly as intended there.

 

If it helps, I’ve also created a JavaScript Full Course for absolute beginners, using a Personal Developer Instance purely as a safe execution environment. It walks through concepts like this step by step, explains why the code works, and is still ongoing. You can find it at the link below.

 

 

 

 

You’re asking the right questions. Everyone who learns JavaScript goes through this exact phase.

 

Hope this helps, and keep going.

 

Thanks,
Bill