アグリゲート
SUM、COUNT、MIN、MAX、LAST、AVG などの 集計 関数を使用してテーブルをクエリします。
注:
ここで説明する機能には、アグリゲート Web サービス プラグインが必要です。
入力フィールド
ターゲットテーブルの任意の要素。さらに、1 つ以上の 集計 関数 (SUM、COUNT、MIN、MAX、LAST、AVG)。
GROUP BYとHAVING句を追加することもできます。
出力フィールド
取得されたレコードのすべてのフィールド値をカプセル化する aggregateResponse 要素。
サンプル SOAP メッセージ
COUNT 集計関数を使用したサンプル SOAP 要求。
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:m="http://www.service-now.com"
xmlns:tns="http://www.service-now.com/map"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<aggregate>
<COUNT>number</COUNT>
<active>true</active>
</aggregate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>COUNT 集計関数呼び出しの結果の応答は次のようになります。
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:m="http://www.service-now.com"
xmlns:tns="http://www.service-now.com/map"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<aggregateResponse>
<aggregateResult>
<avg>2.7200</avg>
</aggregateResult>
</aggregateResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>GROUP BY 句を指定した AVG 集計関数を使用したサンプル SOAP 要求。
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:m="http://www.service-now.com"
xmlns:tns="http://www.service-now.com/map"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<aggregate xmlns="http://www.service-now.com">
<GROUP_BY>category</GROUP_BY>
<active>true</active>
<AVG>severity</AVG>
</aggregate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>GROUP BY 句を使用した AVG 集計関数呼び出しの結果の応答は、次のようになります。
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:m="http://www.service-now.com"
xmlns:tns="http://www.service-now.com/map"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<aggregateResponse>
<aggregateResult>
<avg>1.0000</avg>
<category>database</category>
</aggregateResult>
<aggregateResult>
<avg>3.0000</avg>
<category>hardware</category>
</aggregateResult>
<aggregateResult>
<avg>3.0000</avg>
<category>inquiry</category>
</aggregateResult>
<aggregateResult>
<avg>2.0000</avg>
<category>network</category>
</aggregateResult>
<aggregateResult>
<avg>2.6923</avg>
<category>software</category>
</aggregateResult>
</aggregateResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
エンコードされたクエリを使用して集計をフィルタリングするサンプル SOAP 要求:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:m="http://www.service-now.com"
xmlns:tns="http://www.service-now.com/map"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<aggregate>
<COUNT>number</COUNT>
<active>true</active>
<__encoded_query>number=INC0000001^ORnumber=INC0000002</__encoded_query>
</aggregate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>結果を絞り込むために HAVING を使用したサンプルアグリゲート要求。
HAVING は 4 つのフィールドを取ります。各フィールドは「^」で区切られています。つまり、アグリゲートタイプ、アグリゲートのフィールド、操作タイプ、および比較する値です。
複数の HAVING を要求に追加できるため、HAVING 式を使用できますが、OR はサポートされていません。
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:m="http://www.service-now.com"
xmlns:tns="http://www.service-now.com/map"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<aggregate>
<COUNT>sys_id</COUNT>
<GROUP_BY>internal_type</GROUP_BY>
<HAVING>COUNT^*^>^10</HAVING>
<HAVING>COUNT^*^<^20</HAVING>
<COUNT>sys_id</COUNT>
<active>true</active>
</aggregate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>