Calling multiple functions Script include - Server side

chidanandadhath
Kilo Guru

Is it possible to declare multiple functions inside script include and call it from business rule. 

1 ACCEPTED SOLUTION

Stewe Lundin
Mega Guru

use "this" for calling an internal function in the same script include 

NewInclude.prototype = {
    initialize: function() {},

    myFunction: function() {
        //function code here
    },

    mySecondFunction: function() {
        //function code here
    },

    myThirdFunction: function() {
        //function code here
        // calling an internal function in the same script include user the keyword this.functionname
        this.mySecondFunction();  

    },
    myForthFunction: function() {
        //function code here
        //calling an external fucntion form another script include
        var tool = new mySecondScriptInclude()
        return tool.myExternalSubFunction(arg1,arg2);

    },

    type: 'NewInclude'
};

 

 

View solution in original post

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Yes, that is possible. If you look at the code in this docs article, you can just add more functions like so:

var NewInclude = Class.create();

NewInclude.prototype = {
    initialize: function() {},

    myFunction: function() {
        //function code here
    },

    mySecondFunction: function() {
        //function code here
    },

    type: 'NewInclude'
};

And then call them like this:

var foo =new NewInclude();
foo.myFunction();
foo.mySecondFunction();

Dubz
Mega Sage

Gah. You know when you write out a reply and then scroll down and someone else has written the same thing but quicker...well, that.

chidanandadhath
Kilo Guru

I want to call second function inside first function like

myfunction : function(){

var x=mySecondfunction(<Parameter>)

}

mySecondfunction(<parameter>)

{

 

return X;

}

Stewe Lundin
Mega Guru

use "this" for calling an internal function in the same script include 

NewInclude.prototype = {
    initialize: function() {},

    myFunction: function() {
        //function code here
    },

    mySecondFunction: function() {
        //function code here
    },

    myThirdFunction: function() {
        //function code here
        // calling an internal function in the same script include user the keyword this.functionname
        this.mySecondFunction();  

    },
    myForthFunction: function() {
        //function code here
        //calling an external fucntion form another script include
        var tool = new mySecondScriptInclude()
        return tool.myExternalSubFunction(arg1,arg2);

    },

    type: 'NewInclude'
};