How to get total row count from Rest Message script?

Ankita Kolhe
Tera Contributor

Hi community,

 

Can someone please help how to get the total row count from the below rest message script? I don't want to use 'maxRecordsToReturn' attribute. I want to get all records count from the response.

 

I tried removing maxRecordsToReturn but it's showing me some error.

 

 var requestBody = '{"entityName": "' + search_term + '", "maxRecordsToReturn": 100}';
            var request = new sn_ws.RESTMessageV2('global.sentinel_new', 'GetSearchEntity');
            request.setRequestBody(requestBody);
            var response = request.execute();
            var headers = response.getAllHeaders();
            for (var i in headers) {
                gs.info('123: '+headers[i].name + ': ' + headers[i].value);
            }
            var responseBody = response.getBody();
           
            var JSONData = JSON.parse(responseBody);
            for (var i = 0; i < 100; i++) {
                entitiesArr.push({
                    'gisid': JSONData.entities[i].entity.entityID,
                    'entity_name': JSONData.entities[i].entity.fullBusinessName,
                    'stateCode': JSONData.entities[i].entity.address.stateCode,
                    'countryCode': JSONData.entities[i].entity.address.countryCode,
                    'duns': JSONData.entities[i].entity.duns
                });
 
Thanks
1 ACCEPTED SOLUTION

@Ankita Kolhe This is 99 as your API returns maximum 100 records 

"maxRecordsToReturn": 100

If you wish to get the exact number of records returned by the search term then you need to request your API team to check if any response parameter contains the count of total number of records.

View solution in original post

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Ankita Kolhe If you wish to know the record count from response, one way to do is to check the length of the array in which you are pusing the entities.

 

 var requestBody = '{"entityName": "' + search_term + '", "maxRecordsToReturn": 100}';
            var request = new sn_ws.RESTMessageV2('global.sentinel_new', 'GetSearchEntity');
            request.setRequestBody(requestBody);
            var response = request.execute();
            var headers = response.getAllHeaders();
            for (var i in headers) {
                gs.info('123: '+headers[i].name + ': ' + headers[i].value);
            }
            var responseBody = response.getBody();
           
            var JSONData = JSON.parse(responseBody);
            for (var i = 0; i < 100; i++) {
                entitiesArr.push({
                    'gisid': JSONData.entities[i].entity.entityID,
                    'entity_name': JSONData.entities[i].entity.fullBusinessName,
                    'stateCode': JSONData.entities[i].entity.address.stateCode,
                    'countryCode': JSONData.entities[i].entity.address.countryCode,
                    'duns': JSONData.entities[i].entity.duns
                });
if(entitiesArr){
gs.info(entitiesArr.length); //Give the count of number of records in response
}

Hi @Sandeep Rajput ,

 

entitiesArr length is same as the value (i-1) ie 99. Every time it will be 99 only.

 

Thanks

@Ankita Kolhe This is 99 as your API returns maximum 100 records 

"maxRecordsToReturn": 100

If you wish to get the exact number of records returned by the search term then you need to request your API team to check if any response parameter contains the count of total number of records.