The getAggregateRecord operation Allow to compute aggregate statistics about existing table and column data.
getAggregateRecord
<servicenow.getAggregateRecord>
<tableName>{$ctx:tableName}</tableName>
<sysparmAvgFields>{$ctx:sysparmAvgFields}</sysparmAvgFields>
<sysparmMinFields>{$ctx:sysparmMinFields}</sysparmMinFields>
<sysparmMaxFields>{$ctx:sysparmMaxFields}</sysparmMaxFields>
<sysparmCount>{$ctx:sysparmCount}</sysparmCount>
<sysparmSumFields>{$ctx:sysparmSumFields}</sysparmSumFields>
</servicenow.getAggregateRecord>
Properties
- tableName: Name of the table you want to retrieve a record.
- sysparmAvgFields: A comma-separated list of fields for which to calculate the average value.
- sysparmMinFields: A comma-separated list of fields for which to calculate the minimum value.
- sysparmMaxFields: A comma-separated list of fields for which to calculate the maximum value.
- sysparmCount: You can set this parameter to true for the number of records returned by the query.
- sysparmSumFields: A comma-separated list of fields for which to calculate the sum of the values.
Sample request
Following is a sample request that can be handled by the getAggregateRecord operation.
{
"serviceNowInstanceURL":"https://dev17686.service-now.com",
"username":"admin",
"password":"12345",
"tableName":"incident",
"sysparmAvgFields":"category,active",
"sysparmMinFields":"number",
"sysparmMaxFields":"number",
"sysparmCount":"true",
"sysparmSumFields":"priority"
}
Sample response
Given below is a sample response for the getAggregateRecord operation.
{
"result":{
"stats":{
"count":"89"
}
}
}
Related ServiceNow documentation
https://developer.servicenow.com/app.do#!/rest_api_doc?v=jakarta&id=r_AggregateAPI-GET
Following example illustrates how to connect to ServiceNow with the init operation and getAggregateRecord operation.
- Create a sample proxy as below :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="getAggregateRecord"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="serviceNowInstanceURL" expression="json-eval($.serviceNowInstanceURL)"/>
<property name="username" expression="json-eval($.username)"/>
<property name="password" expression="json-eval($.password)"/>
<property name="tableName" expression="json-eval($.tableName)"/>
<property name="sysparmAvgFields" expression="json-eval($.sysparmAvgFields)"/>
<property name="sysparmMinFields" expression="json-eval($.sysparmMinFields)"/>
<property name="sysparmMaxFields" expression="json-eval($.sysparmMaxFields)"/>
<property name="sysparmCount" expression="json-eval($.sysparmCount)"/>
<property name="sysparmSumFields" expression="json-eval($.sysparmSumFields)"/>
<servicenow.init>
<serviceNowInstanceURL>{$ctx:serviceNowInstanceURL}</serviceNowInstanceURL>
<username>{$ctx:username}</username>
<password>{$ctx:password}</password>
</servicenow.init>
<servicenow.getAggregateRecord>
<tableName>{$ctx:tableName}</tableName>
<sysparmAvgFields>{$ctx:sysparmAvgFields}</sysparmAvgFields>
<sysparmMinFields>{$ctx:sysparmMinFields}</sysparmMinFields>
<sysparmMaxFields>{$ctx:sysparmMaxFields}</sysparmMaxFields>
<sysparmCount>{$ctx:sysparmCount}</sysparmCount>
<sysparmSumFields>{$ctx:sysparmSumFields}</sysparmSumFields>
</servicenow.getAggregateRecord>
<respond/>
</inSequence>
<outSequence>
<log/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
- Create a JSON file named getAggregateRecord.json and add the configurations given below:
{
"serviceNowInstanceURL":"https://dev17686.service-now.com",
"username":"admin",
"password":"12345",
"tableName":"incident",
"sysparmAvgFields":"category,active",
"sysparmMinFields":"number",
"sysparmMaxFields":"number",
"sysparmCount":"true",
"sysparmSumFields":"priority"
}
-
Replace the credentials with your values.
-
Execute the following curl command:
curl http://localhost:8280/services/getAggregateRecord -H "Content-Type: application/json" -d @getAggregateRecord.json
- ServiceNow returns a JSON response similar to the one shown below:
{
"result":{
"stats":{
"count":"89"
}
}
}