Getting count in REST API

Arjun King
Tera Contributor

Hi ,

How to get row count  for table API in Rest.In simple i want to get  no of records extracted using Table api.

Ex:

https://instance.service-now.com/api/now/table/incident?sysparm_query=sys_created_onBETWEENjavascript:gs.dateGenerate('2019-04-03','00:00:00')@javascript:gs.dateGenerate('2019-04-03','16:59:59')^incident_state=4&sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_fields=number%2Ccaller_id%2Cincident_state%2Ccontact_type%2Csubcategory%2Cu_tertiary_category%2Cshort_description%2Cu_vendor_name%2Cu_alternate_contact_number%2Cu_alternate_phone%2Cu_alternate_email_address%2Ccategory%2Cimpact%2Curgency%2Cpriority%2Copened_by%2Copened_at%2Cu_case_type%2Cu_next_action_2%2Cu_next_action_1%2Cassigned_to%2Cu_callback_start_date%2Cclose_code%2Cu_closure_codes_2%2Cclose_notes%2Cdescription&sysparm_limit=100&sysparm_offset=0    --> for this i need to get the count of extracted records.

 

Thanks,

Arjun.

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Arjun,

Parse the json response; since multiple records are there the json would contain array of json objects.

you can get length from that

var parser = new JSONParser();

var parsedData = parse.parse(response);

var length = parsedData.result.length; // whenever system returns list of records result is the parent key so it will have array of objects within it

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, I am using Table API

Akash4
Kilo Sage
Kilo Sage

Hi Arjun,

You can use the URL extension for this, add sys parameter values. You can try using REST API Explorer for perfect results in the initial stage, sysparm_count=true will help you here. The final URL looks like this:

https://dev1234.service-now.com/api/now/v1/table/incident?sysparm_query=WHATSOEVERYOUWANT&sysparm_li...

Regards, Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

hello Akash,

 

 i tried this ,but of no use

 

Thanks,

Arjun