agregado

  • Versão de lançamento: Zurich
  • Atualizado 31 de jul. de 2025
  • 1 min. de leitura
  • Consulte uma tabela usando um agregado Função incluindo SOMA, CONTAGEM, MÍNIMO, máximo, ÚLTIMO, e AVG.

    Nota:
    A funcionalidade descrita aqui requer o serviço web agregado plug-in.

    Campos de entrada

    Qualquer elemento da tabela de destino. Além disso, um ou mais dos agregado FUNÇÕES (SOMA, COUNT, MIN, MAX, LAST, e AVG).

    Um GROUP BY e uma cláusula HAVING também podem ser adicionados.

    Campos de saída

    Um AgregateResponse elemento encapsulando todos os valores de campo do registro recuperado.

    Mensagens SOAP de amostra

    Solicitação SOAP de amostra usando a função de agregação de CONTAGEM.

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

    A resposta resultante de uma chamada de função de agregação de CONTAGEM é semelhante a esta:

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

    Solicitação SOAP de amostra usando a função de agregação AVG com uma cláusula 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>

    A resposta resultante de uma chamada de função de agregação do AVG com uma cláusula GROUP BY é semelhante a esta:

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

    Solicitação SOAP de amostra usando uma consulta codificada para filtrar o agregado:

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

    Solicitação agregada de amostra usando a NECESSIDADE DE restringir os resultados.

    Tem quatro campos. Cada campo é delimitado por "": O tipo de agregação, o campo da agregação, o tipo de operação e o valor a ser comparado.

    Mais de um HING pode ser adicionado à solicitação, portanto, você pode usar expressões HAVING, mas não há suporte para OU.

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