{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1369,"path":"api-reference/web-services/t_CustomizeResponse.md","title":"Customize response","bundle":null,"doc_type":null,"release":"australia","body":"\n# Customize response\n\nFollow this example to customize and control the XML payload of a SOAP response.\n\n## Before you begin\n\nRole required: web\\_service\\_admin or admin\n\n## Procedure\n\n1.  Create a customized XML document using the [XMLDocument](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_XMLDocumentScriptObject.md) script include object.\n\n    **Note:** When creating a scripted web service in a scoped application you must use the [XMLDocument2](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_XMLDocument2ScopedAPI.md) API.\n\n2.  Set its document element to the variable *response.soapResponseElement* in a scripted web service.\n\n    For example, the following scripted web service script:\n\n    ```\n    var xmldoc = new XMLDocument2();\n        xmldoc.parseXML(\"<myResponse></myResponse>\");\n        xmldoc.createElementWithTextValue(\"element_one\", \"test\");  \n        xmldoc.createElementWithTextValue(\"element_two\", \"new2 value\");  \n    \n        var el = xmldoc.createElement(\"element_three\");\n        xmldoc.setCurrentElement(el);  \n        xmldoc.createElementWithTextValue(\"newChild\", \"test child element\");\n    \n        response.soapResponseElement = xmldoc.getDocumentElement();\n    ```\n\n    Is used to accept the following request:\n\n    ```\n    <soapenv:Envelope \n       xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" \n       xmlns:tes=\"http://www.service-now.com/TestCustomResponse\">\n       <soapenv:Header/>\n       <soapenv:Body>\n          <tes:execute/>\n       </soapenv:Body>\n    </soapenv:Envelope>\n    ```\n\n    Which will respond with the following SOAP response:\n\n    ```\n    <soapenv:Envelope \n        xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" \n        xmlns:tes=\"http://www.service-now.com/TestCustomResponse\">\n       <soapenv:Header/>\n       <soapenv:Body>\n          <myResponse>\n             <element_one>test</element_one>\n             <element_two>new2 value</element_two>\n             <element_three>\n                <newChild>test child element</newChild>\n             </element_three>\n          </myResponse>\n       </soapenv:Body>\n    </soapenv:Envelope>\n    ```\n\n    WSDL support will need to be created externally. The SOAP endpoint will need to be referred back to the scripted web service in question.\n\n\n**Parent Topic:**[Scripted SOAP web services](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/web-services/c_ScriptedWebServices.md)\n\n"}}