How to include any script include in scripted rest api

Sneha39
Mega Guru

Hi,

I want to call script include inside scripted rest api.

Kindly let me know how to include it.

Thanks in advance

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Sneha,



You would call it the same way you do from any server side scripting area:



Use script includes


Hello,


I need to create a Webservice API where input is: Sys ID of any record and output is: all *related* active records to that sys id. The relationships between the tables is maintained in Relationships under system definition.


Could you please guide me how to implement this? Sample code would be great.


Input: Sys ID of the record
Output: All *RELATED* active records from *VARIOUS* tables (in the following JSON format):
{
"result": [
{
"Sys ID": "5520267",
"CI Name": "Record 1",
"Table Name": "u_table_a"
},
{
"Sys ID": "5520367",
"CI Name": "Record 2",
"Table Name": "u_table_a"
},
{
"Sys ID": "8331210",
"CI Name": "Record 1",
"Table Name": "u_table_b"
},
{
"Sys ID": "8321210",
"CI Name": "Record 2",
"Table Name": "u_table_b"
},
{
"Sys ID": "3042006",
"CI Name": "Record 3",
"Table Name": "u_table_b"
},
{
"Sys ID": "4509847",
"CI Name": "Record 1",
"Table Name": ""u_table_c"
}
{
"Sys ID": "4509247",
"CI Name": "Record 2",
"Table Name": ""u_table_c"
}
]
}

killswitch1111
ServiceNow Employee
ServiceNow Employee

Sneha,



You don't need to include it.   When you create your Script Include, it is loaded into the accessible script cache.   From inside your Scripted Rest API you can directly call the Script Include (as long as it is Active) in this way:



Script Include Name: MyScriptInclude



If your API is in the same scope as your Script Include:



var myinclude = new MyScriptInclude();



If it is in a different scope:



var myinclude = new script_include_scope_prefix.MyScriptInclude();



Thanks,


Chris