how to pass two parameter(numbers) from client script and get response(addition of two numbers) from script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2020 10:05 AM
I am new to service-now
how to pass two parameter and get addition of those numbers from script include
and Parameters should be handled in such a way that it accepts Server side call as well as Client side call.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2020 03:38 PM
BTW, I've set Validation Regex on all fields to be "Number" and also set Default Values on Field1 and Field2 to be 0 and also check "Mandatory" on those fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2020 11:25 AM
To make the Script Include work when called by a client or server script, make sure the Client callable box is checked, then building on the script hozawa provided, here's what it would look like to also work with a server call - which is overkill for this simple example, but it gives you the same structure you would use for more robust requirements.
var calculator = Class.create();
calculator.prototype = Object.extendsObject(AbstractAjaxProcessor, {
calculatesum: function(num1, num2) {
if(num1){
var number1 = num1;
}
else{
var number1 = parseInt(this.getParameter('sysparm_field1'));
}
if(num2){
var anumber2 = num2;
}
else{
var number2 = parseInt(this.getParameter('sysparm_field2'));
}
return (number1 + number2).toString();
},
type: 'calculator'
});