---
sourceDocument: Xanadu API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# 応答のカスタマイズ

# 応答のカスタマイズ {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：2分

この例に従って、SOAP 応答の XML ペイロードをカスタマイズおよび制御します。

## 始める前に

必要なロール：web_service_admin または admin

## 手順

1. [XMLDocument](https://servicenow-prod.fluidtopics.net/6f9ijLWy189XOdOeGTOEXA "XML ドキュメント (文字列) から XML データを解析および抽出するための JavaScript オブジェクトラッパー。") スクリプトインクルードオブジェクトを使用して、カスタマイズされた XML ドキュメントを作成します。  
   注:  
   スコープ対象のアプリケーションでスクリプト化された Web サービスを作成する場合は、 [XMLDocument2](https://servicenow-prod.fluidtopics.net/BZgu_8cumIWb86I6Btksmw#c_XMLDocument2ScopedAPI "XMLDocument2 API は、XML 文字列から XML データを解析および抽出するための JavaScript オブジェクトラッパーです。") API を使用する必要があります。
2. ドキュメント要素をスクリプト利用 Web サービスの変数 <var class="keyword varname">response.soapResponseElement</var> に設定します。  
   たとえば、次のスクリプト利用 Web サービススクリプトの場合

       var xmldoc = new XMLDocument2();
           xmldoc.parseXML("<myResponse></myResponse>");
           xmldoc.createElementWithTextValue("element_one", "test");  
           xmldoc.createElementWithTextValue("element_two", "new2 value");  

           var el = xmldoc.createElement("element_three");
           xmldoc.setCurrentElement(el);  
           xmldoc.createElementWithTextValue("newChild", "test child element");

           response.soapResponseElement = xmldoc.getDocumentElement();

   次の要求を受け入れるために使用されます。

       <soapenv:Envelope 
          xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
          xmlns:tes="http://www.service-now.com/TestCustomResponse">
          <soapenv:Header/>
          <soapenv:Body>
             <tes:execute/>
          </soapenv:Body>
       </soapenv:Envelope>

   これは、次の SOAP 応答で応答します。

       <soapenv:Envelope 
           xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
           xmlns:tes="http://www.service-now.com/TestCustomResponse">
          <soapenv:Header/>
          <soapenv:Body>
             <myResponse>
                <element_one>test</element_one>
                <element_two>new2 value</element_two>
                <element_three>
                   <newChild>test child element</newChild>
                </element_three>
             </myResponse>
          </soapenv:Body>
       </soapenv:Envelope>

   WSDL サポートは外部で作成する必要があります。SOAP エンドポイントは、問題のスクリプト利用 Web サービスを再び参照する必要があります。

