Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to call script include from another script include.

Priya Gautum
Kilo Guru

Hi All

How can we call script include a function to another script include?

I have one script include function- "countKBArticle: function()" and need to call this function in the new script include but not sure how to call.

Regards,

Priya

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Priya,

1. You can call script include from another script include as below:

var osi = new otherScriptInclude();
osi.otherScriptIncludeFunction();

2. Way to call script include from Business rule, workflow activity or or from server side script:

var osi = new ScriptIncludeName();
osi.scriptIncludeFunction();

3. Way to call script include from client script, Catalog Client Script or UI policies

var deptName = g_form.getValue('department');
var si =new GlideAjax('ScriptIncludeName'); 
si.addParam('sysparm_name','scriptIncludeFunction'); // you need to use sysparm_name for calling function
si.addParam('sysparm_dept',deptName); // you can add any parameter here in place of sysparm_dept. like sys_dept
si.getXML(setDepartmentHead);

function setDepartmentHead(response){

var deptHead = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('u_department_head',deptHead);

}

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

4 REPLIES 4

Jace Benson
Mega Sage

Just like you can from any other server scripting area;

Here's an OOB example from the "ValidateSchedule" script include;

find_real_file.png

 

Community Alums
Not applicable

Hi Priya,

Please use the below method.

 

Script Include 1:

Name: MySI

getDemo: function()

{

   gs.log("getDemo");

}

 

Script Include 2:

Name: MySITest

getDemoTest: function()

{

   var obj = new MySI();     //Create an object of Script include

   obj.getDemo();              //Call the function using the object of script include.

}

 

Output: 

LOG: getDemo

 

Regards

Santosh Poudel

Dilip Puligilla
Giga Guru

HI Priya

var a = new otherScriptInclude();
a.otherScriptIncludeFunction();

 

Please replace your ScriptInclude name 

 

Thanks and Regards

Dilip Puligilla

AbhishekGardade
Giga Sage

Hello Priya,

1. You can call script include from another script include as below:

var osi = new otherScriptInclude();
osi.otherScriptIncludeFunction();

2. Way to call script include from Business rule, workflow activity or or from server side script:

var osi = new ScriptIncludeName();
osi.scriptIncludeFunction();

3. Way to call script include from client script, Catalog Client Script or UI policies

var deptName = g_form.getValue('department');
var si =new GlideAjax('ScriptIncludeName'); 
si.addParam('sysparm_name','scriptIncludeFunction'); // you need to use sysparm_name for calling function
si.addParam('sysparm_dept',deptName); // you can add any parameter here in place of sysparm_dept. like sys_dept
si.getXML(setDepartmentHead);

function setDepartmentHead(response){

var deptHead = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('u_department_head',deptHead);

}

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade