We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Scripted SOAP Service Response

sharmarohit
Tera Contributor

We have a requirement to process the SOAP inbound request and response must be in the specific format as below, we are able to generate the XML document but whatever we are generating that is the part of SOAP Body tag. but instead of SOAP Body we need to modify the entire XML response.

Expected response XML is below:

 

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <SOAP-ENV:Header>
      <wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">https://urldefense.com/v3/tiXREV_TXP3rxh9gipFq9ui3G4XWxNLZNa2lDs0kX-vgYk7mCHbUj2ZLI-w47Z2fhAuTI70TS4FY-1Rn8IXM$ </wsa:Action>
      <tns2:Source xmlns:tns2="http://group.xyz.com/contract/vho/header/v1">
         <tns2:CountryCode>UK</tns2:CountryCode>
         <tns2:Operator/>
         <tns2:Division/>
         <tns2:System>ABC</tns2:System>
         <tns2:Timestamp>2023-08-16T16:00:00</tns2:Timestamp>
         <tns2:Identity>
            <tns2:Token>807251125</tns2:Token>
         </tns2:Identity>
         <tns2:LanguageCode>?</tns2:LanguageCode>
      </tns2:Source>
      <tns2:Destination xmlns:tns2="http://group.xyz.com/contract/vho/header/v1">
         <tns2:Operator/>
         <tns2:Division/>
         <tns2:System>Remedy</tns2:System>
         <tns2:Timestamp>2023-08-16T16:00:00</tns2:Timestamp>
      </tns2:Destination>
      <tns2:Correlation xmlns:tns2="http://group.xyz.com/contract/vho/header/v1">
         <tns2:ConversationID>123456</tns2:ConversationID>
      </tns2:Correlation>
      <tns2:ResultStatus xmlns:tns2="http://group.xyz.com/contract/vho/header/v1">
         <ws-bf:Timestamp xmlns:ws-bf="http://docs.oasis-open.org/wsrf/bf-2">2024-11-04T13:14:40.637Z</ws-bf:Timestamp>
         <tns1:ReasonCode xmlns:tns1="http://group.xyz.com/contract/vfo/fault/v1">000</tns1:ReasonCode>
         <tns1:Message xmlns:tns1="http://group.xyz.com/contract/vfo/fault/v1">Success</tns1:Message>
      </tns2:ResultStatus>
   </SOAP-ENV:Header>
   <SOAP-ENV:Body>
      <tns:CreateIncidentVBMResponse xmlns:tns="http://group.xyz.com/schema/vbm/service/incident/v1">
         <tns:IncidentVBO>
            <cmn:IDs xmlns:cmn="http://group.xyz.com/schema/common/v1">
               <cmn:ID>NET09584847</cmn:ID>
            </cmn:IDs>
            <cmn:Status xmlns:cmn="http://group.xyz.com/schema/common/v1">Open</cmn:Status>
         </tns:IncidentVBO>
      </tns:CreateIncidentVBMResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 

 

 

1 REPLY 1

sharmarohit
Tera Contributor
To present the response without showing the function name, remove the function wrapper from the script and execute the call directly within the script. This prevents the function name from appearing in the output and enables the desired response format to be displayed correctly.
sharmarohit_0-1783866545415.png

 

sharmarohit_1-1783866565619.png

 

 

 

 

Solution Code:

 

  try {
      responseXMLDoc = new XMLDocument("<tns:CreateIncidentVBMResponse xmlns:tns='http://group.xyz.com/schema/vbm/service/incident/v1' />");
      incVBO = responseXMLDoc.createElement("tns:IncidentVBO");
      responseXMLDoc.setCurrent(incVBO);
      var cmnIDs = responseXMLDoc.createElement('cmn:IDs');
      cmnIDs.setAttribute("xmlns:cmn", "http://group.xyz.com/schema/common/v1");
      responseXMLDoc.setCurrent(cmnIDs);
      var cmnID = responseXMLDoc.createElement('cmn:ID', 'NET09584847');
      responseXMLDoc.setCurrent(incVBO);
      var status = responseXMLDoc.createElement('cmn:Status', 'Open');
      status.setAttribute("xmlns:cmn", "http://group.xyz.com/schema/common/v1");
      response.soapResponseElement = responseXMLDoc.getDocumentElement();

  } catch (err) {
      response.errorMessage = err.message;
  }