---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Customize response

# Customize response {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

Follow this example to customize and control the XML payload of a SOAP
response.

## Before you begin

Role required: web_service_admin or admin

## Procedure

1. Create a customized XML document using the [XMLDocument](https://servicenow-prod.fluidtopics.net/fj73pS1Sp0ypxq3F1UcZGA "A JavaScript object wrapper for parsing and extracting XML data from an XML document (String).") script include object.  
   Note:  
   When creating a scripted web service in a scoped application you must use the [XMLDocument2](https://servicenow-prod.fluidtopics.net/YPBJ89gVrpIarVZ9NzmJgA#c_XMLDocument2ScopedAPI "The XMLDocument2 API is a JavaScript object wrapper for parsing and extracting XML data from an XML string.") API.
2. Set its document element to the variable <var class="keyword varname">response.soapResponseElement</var> in a scripted web service.  
   For example, the following scripted web service script:

       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();

   Is used to accept the following request:

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

   Which will respond with the following SOAP response:

       <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 support will need to be created externally. The SOAP endpoint will need
   to be referred back to the scripted web service in question.

