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 10:11 AM
In client side
var ga = new GlideAjax('ParentChildSync'); // SI Name
ga.addParam( 'sysparm_name', 'Replicate'); // Function Name
ga.addParam('sysparm_state',parentInc); //1st
ga.addParam('sysparm_test','tesd');//2nd
ga.getXML(HelloWorldParse);
in server side
var uid1 = this.getParameter('sysparm_state');
var uid2 = this.getParameter('sysparm_test');
Pranav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2020 10:13 AM
Hi,
You could perform the addition in client script itself, no need of Server Side.
var a = 5;
var b = 5;
var ans = a+b;
alert(ans); //This will give 10
Regards,
JAS

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2020 10:24 AM
Hello Yogesh,
Please refer below link it will show how to pass multiple parameters to script include,
Hope this will help you.
Kindly mark an answer as correct and helpful if it will resolve your query.
Regards,
Akshata

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2020 11:03 AM
I'm assuming that you want to study AJax call.
I've created 3 variables: field1, field2, sum
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('calculator');
ga.addParam('sysparm_name', "calculatesum");
ga.addParam('sysparm_field1', g_form.getValue("field1"));
ga.addParam('sysparm_field2', g_form.getValue("field2"));
ga.getXMLAnswer(function(response) {
g_form.setValue('sum', response);
});
}
Script Include (Server side):
var calculator = Class.create();
calculator.prototype = Object.extendsObject(AbstractAjaxProcessor, {
calculatesum: function() {
var number1 = parseInt(this.getParameter('sysparm_field1'));
var number2 = parseInt(this.getParameter('sysparm_field2'));
return (number1 + number2).toString();
},
type: 'calculator'
});