aggregate

  • Freigeben Version: Washingtondc
  • Aktualisiert 1. Februar 2024
  • 1 Minute Lesedauer
  • Fragen Sie eine Tabelle mit einer aggregate-Funktion einschließlich SUMME, ANZAHL, MIN, MAX, LETZTER und DURCHSCHNITT ab.

    Hinweis:
    Die hier beschriebene Funktionalität erfordert das Plugin „Aggregate Web Service“.

    Eingabefelder

    Jedes beliebige Element der Zieltabelle. Darüber hinaus eine oder mehrere der aggregate-Funktionen (SUMME, ANZAHL, MIN, MAX, LETZTER und DURCHSCHNITT).

    Eine Klausel „GROUP BY“ und „HAVING“ kann ebenfalls hinzugefügt werden.

    Ausgabefelder

    Ein Element aggregateResponse, das alle Feldwerte für den abgerufenen Datensatz enthält.

    Beispiel für SOAP-Nachrichten

    Beispiel einer SOAP-Anforderung mit der Zusammenfassungsfunktion ANZAHL.

    <?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>

    Die resultierende Antwort eines ANZAHL-Zusammenfassungsfunktionsaufrufs sieht folgendermaßen aus:

    <?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>

    Beispiel einer SOAP-Anforderung mit DURCHSCHNITT-Zusammenfassungsfunktion mit einer Klausel GROUP BY.

    <?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>

    Die resultierende Antwort eines DURCHSCHNITT-Zusammenfassungsfunktionsaufrufs mit einer Klausel GROUP BY sieht folgendermaßen aus:

    <?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>
    

    Beispiel einer SOAP-Anforderung mit einer codierten Abfrage zum Filtern der Zusammenfassung:

    <?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>

    Beispiel einer Zusammenfassungsanforderung mit HAVING, um die Ergebnisse einzugrenzen.

    HAVING braucht vier Felder. Jedes Feld wird durch „^“ begrenzt: der Zusammenfassungstyp, das Feld der Zusammenfassung, der Vorgangstyp, und der zu vergleichende Wert.

    Es können mehr als eine HAVING-Klausel zur Anforderung hinzugefügt werden. Sie können also HAVING-Ausdrücke verwenden, OR wird jedoch nicht unterstützt.

    <?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>