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

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.

AparnaSahu
Kilo Sage

Hi @StacyLen ,

You can also try "ServiceNow snd_xplore.do" as well. Xplore is used to improve development activities and support for instances.

Please mark helpful if it helps.

Thanks,

Aparna

Deepak Shaerma
Mega Sage

Hi @StacyLen 

Click on ALL and open your Application Navigator --> Write sys.scripts.modern.DO    and Hit Enter
And paste your script there.

DeepakShaerma_0-1766984453152.png

 



Happy to help! ‌‌
To help others in the community find this solution, kindly mark this response as the Correct Answer ‌‌ and Helpful‌‌.
Warm Regards,
Deepak Sharma
Community Rising Star 2025

Sarthak Kashyap
Mega Sage

Hi @StacyLen ,

 

Please navigate to All< System Definition < Script - background

SarthakKashyap_0-1766990433170.png

 

 

Paste your code and run it 

SarthakKashyap_1-1766990487790.png

 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak