How to get the incidents having same caller id through rest message ?

KM SN
Tera Expert

When I am creating an incident in one instance, I want to check current caller id with another instance Incidents if there exist an even one incident. the current incident should not be created and should show pop up. for that  I am trying to get the incidents data by passing caller id value.

but somehow I am messing up with something which I am not able to figure out can someone help me out to figure out what is happening, and modifications need to be done?



I-1.pngI-2.png

2 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@KM SN Can you check if your query parameter name is correct? Can you call the same API via browser?

View solution in original post

Sanjeev Kumar1
Kilo Sage

Hi  Mmani,

On the Incident form, we have a related list of "Incident by same Caller"

SanjeevKumar1_0-1722346076190.png

 

If you want to get into REST API, write Scripted REST API.

Let me know if you need help writing REST API.

I am giving you a code that you can use in Your REST API.

 

 

var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery("caller_id=77ad8176731313005754660c4cf6a7de");
grIncident.orderByDesc('number');
grIncident.setLimit(20);
grIncident.query();
while (grIncident.next()) {
    gs.info('number: ' + grIncident.getValue('number'));
    gs.info('opened_at: ' + grIncident.getValue('opened_at'));
    gs.info('short_description: ' + grIncident.getValue('short_description'));
    gs.info('caller_id: ' + grIncident.getValue('caller_id'));
}

 

 

OR

You can user OOB REST API on incident tale

https://<instance_name>.service-now.com/api/now/table/incident?sysparm_query=caller_id.email=john.doe@example.com

For more detail about REST API Explorer

 

 

Thanks,

Sanjeev Kumar

 

 

 

View solution in original post

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@KM SN Can you check if your query parameter name is correct? Can you call the same API via browser?

I just named as number but  I neither added it to the end point nor in http request query parameters of REST message ? it that works ?

I didn't get you what it mean by calling through via browser?

GET APIs can simply be tested by providing their URL in the browser here is an example https://fake-json-api.mock.beeceptor.com/users

Sanjeev Kumar1
Kilo Sage

Hi  Mmani,

On the Incident form, we have a related list of "Incident by same Caller"

SanjeevKumar1_0-1722346076190.png

 

If you want to get into REST API, write Scripted REST API.

Let me know if you need help writing REST API.

I am giving you a code that you can use in Your REST API.

 

 

var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery("caller_id=77ad8176731313005754660c4cf6a7de");
grIncident.orderByDesc('number');
grIncident.setLimit(20);
grIncident.query();
while (grIncident.next()) {
    gs.info('number: ' + grIncident.getValue('number'));
    gs.info('opened_at: ' + grIncident.getValue('opened_at'));
    gs.info('short_description: ' + grIncident.getValue('short_description'));
    gs.info('caller_id: ' + grIncident.getValue('caller_id'));
}

 

 

OR

You can user OOB REST API on incident tale

https://<instance_name>.service-now.com/api/now/table/incident?sysparm_query=caller_id.email=john.doe@example.com

For more detail about REST API Explorer

 

 

Thanks,

Sanjeev Kumar