The CreatorCon Call for Content is officially open! Get started here.

how to pass two parameter(numbers) from client script and get response(addition of two numbers) from script include

Yogesh Kale
Mega Contributor

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.

6 REPLIES 6

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.

Brad Bowman
Kilo Patron
Kilo Patron

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'
});