Domain specific query in a scripted rest api

sreedharkaliset
Mega Expert

Hi All,

I have a requirement where I a third party system pulls records out of service now. Instance is a domain separated and I wrote a scripted rest API to retrieve the records and send the response.

The scripted rest API is taking too long when executed and so third party tool is not able to retrieve records. Same script is working fine in instance that is not domain separated.

I added ritm.addDomainQuery('sys id of domain') in glide record but it is not working. Please let me know how to overcome this

Below is the scripted rest API

var ritm=new GlideRecord('sc_req_item');

ritm.addDomainQuery('a58a46e313ddc300c8dd59722244b048');

ritm.addQuery('state',1);

ritm.query();

while(ritm.next()){

//response

}

4 REPLIES 4

Sanjeev Kumar1
Kilo Sage

Hi ,



you are using addDomainQuery befor query() function.



so please see following how to use it


GlideRecord - ServiceNow Wiki


Hi Sanjeev,



we tried to use domain query as suggested in that link, but our gliderecord is timing out.


we believe this is issue with domain separated instance as it was working properly in individual instance


Please help us on how make the gliderecord query domain specific so that it returns data faster



Thanks


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"
}
]
}

Did you find the solution for this, if so please help me i have similar request.

 

Thanks