program addition of two numbers in java script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2024 10:06 PM
please explain addition of two numbers in java script in service now and i need a code for that.
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 04:30 AM
Hi @ramprakashd In JavaScript, adding two numbers is straightforward. You just use the + operator. For example:
var num1 = 5;
var num2 = 10;
var sum = num1 + num2;
gs.info("The sum is: " + sum); // gs.info is used to log messages
In business rule you can write like this
(function executeRule(current, previous /*null when async*/) {
var num1 = 5;
var num2 = 10;
var sum = num1 + num2;
gs.addInfoMessage("The sum of " + num1 + " and " + num2 + " is: " + sum);
})(current, previous);
Learn JavaScript from scratch

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 04:42 AM
@ramprakashd This is a very basic question, the script varies depending on from where you are executing.
Here is an example of a client script
function onLoad(){
var num1 = 10;
var num2 = 20;
// Adding the numbers
var sum = addNumbers(num1, num2);
// Display the result
alert('The sum of ' + num1 + ' and ' + num2 + ' is: ' + sum);
}
function addNumbers(a, b) {
return a + b;
}