How to retrieve all the records from Scorecard API call?

Bharatha
Tera Contributor

Hello,

  • Problem 1: Unable to parse all the records from a Scorecard API response despite sysparm_limit is set to -1
  • Problem 2: Unable to filter for specific field from the JSON response

Context: With Namespace = now, API = Scorecard API, and API Version = latest I am trying to get values returned from a Formula Indicator. Although there are no errors, the response does not consists of all the records that I hoped would get. There are only 10 records parsed while there are more than 100 records to be parsed. Below is the code I have written on Service Portal widget editor.

(function() {

	var request = new sn_ws.RESTMessageV2();

	request.setEndpoint('https://my_instance.service-now.com/api/now/pa/scorecards?sysparm_uuid=<formula-indicator-sys_id>&sysparm_breakdown=<breakdown-sys_id>&sysparm_sortby=VALUE&sysparm_sortdir=DESC&sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_limit=-1');
	request.setHttpMethod('GET');
	var user = 'admin';
	var pass = 'admin';
	request.setBasicAuth(user,pass);
	request.setRequestHeader("Accept","application/json");

	var response = request.execute();
	if (response.haveError()) {
		var scoreCount = "No Scores Available";
	} else {
		var scoreCount = 0;
		var scores = JSON.parse(response.getBody());

		for (app = 0; app < scores.result.length; app++) {
			if(Number(data.scores.result[app].value_formatted) >= 64.99) {
				scoreCount+=1;
			}
		}
	}
})();

 Intent behind Problem 1: To count number of records (Services) with scores >= 65

Intent behind Problem 2: There are several key value pairs within one record of result. For example, see below.

{
  "result": [
    {
      "indicator": "Risk Rating",
      "gap_formatted": "14.89",
      "benchmarking": false,
      "frequency_label": "Monthly",
      "changeperc_formatted": "17.1%",
      "direction_label": "Minimize",
      "precision": 2,
      "breakdown": "Service Offering",
      "personal_target": null,
      "description": null,
      "value_color": "#8b0000",
      "uuid": "abc1:abcd3:abcd",
      "frequency": 40,
      "gap": 14.891278276074814,
      "value_unit": "85.11",
      "indicator_frequency": 40,
      "value": 85.10872172392519,
      "indicator_aggregate": 1,
      "key": false,
      "indicator_frequency_label": "Monthly",
      "direction": 2,
      "element": "Service name here",
      "period_title": "Feb 2022",
      "period": "Feb 2022",
      "target_formatted": "100.00",
      "change": 12.404903532915114,
      "gapperc_formatted": "14.9%",
      "realtime_enabled": false,
      "changeperc": 17.062244929591603,
      "target": 100,
      "unit": "#",
      "value_formatted": "85.11",
      "name": "Risk Rating > Service Offering = <Service name here>",
      "formula": "formula used here, returns the score",
      "gapperc": 0.14891278276074815,
      "change_formatted": "12.40",
      "favorite": false,
      "personal_target_formatted": ""
    }
]
}

 

From the above response, all that I care about is just the field "value_formatted". How do I retrieve only value_formatted values for all the records? I have tried to add sysparm_fields but it doesn't seem to have made any changes in response.

 

Please help.!

1 ACCEPTED SOLUTION

Pedro Grilo1
Mega Sage

Hi!

 

For the first issue I believe you are seeing 10 entries as it is being paged.

Can you try adding something like "&sysparm_per_page=-1" and check if you get more results?

 

Best regards,

Pedro

View solution in original post

3 REPLIES 3

Pedro Grilo1
Mega Sage

Hi!

 

For the first issue I believe you are seeing 10 entries as it is being paged.

Can you try adding something like "&sysparm_per_page=-1" and check if you get more results?

 

Best regards,

Pedro

Bharatha
Tera Contributor

Thank you much.! that was pretty simple and straight forward, I do not know why I missed it all these days. I now have the desired result. 

VaranAwesomenow
Mega Sage

I don thk the sysparm_fields is not valid method for scorecards api.

So you have to find way to process the data once its retrieved. but there are lot of other functions that API is offering, did you give it a try.

find_real_file.png