Integrate > Service Manager integration methods and tools > Web Services > SOAP API > Consume an external Web Service > Best practices for writing a JavaScript to consume a Web Service

Best practices for writing a JavaScript to consume a Web service

Never modify the JavaScript that is automatically generated by WSDL2JS unless you are specifically instructed to do so by Service Manager Customer Support. To invoke the Web service, write a JavaScript record that calls the functions generated by WSDL2JS. The JavaScript that invokes an external Web service should perform the following tasks:

  1. Create the Service Object.
  2. Create the Request Object.
  3. Fill the Request Object with information that defines the request.
  4. Invoke the Service Object and pass in the Request Object.
  5. Return either the Response Object, an instance of the Response Object, or a specific value of that instance.
  6. Perform error handling to test each response. Use try {…}, throw {…}, catch {…}, and the isFault function.

As a best practice, do not reuse the names of variables and functions in the calling JavaScript that are the names of variables and functions in the generated script. This can help avoid confusion.

Caution Never use the “new” keyword on a subordinate object unless it is an array. Unlike conventionally compiled applications that invoke a Web service, the generated function objects described in this document already use “new” when instantiating all children, so it is not necessary to do so in the calling JavaScript. The only exception is for arrays, where you use the newInstance() function to generate the array and fill its elements.