Class Service

Base class of Services.

A service represents a call-specific configuration. Any configuration set here is local to the currently executing call.

See Also:

All Known Subclasses 

FTPService, HTTPFormService, HTTPService, SOAPService

Property Summary 

PropertyDescription
URL: StringReturns the current URL, excluding any custom query parameters.
configuration: ServiceConfig (read-only)Returns the Service Configuration.
credentialID: StringReturns the ID of the currently associated Credential.
mock: BooleanReturns the status of whether this service is executing in mock mode.
requestData: Object (read-only)Returns the property that stores the object returned by createRequest.
response: Object (read-only)Returns the property that stores the object returned by the service.
throwOnError: BooleanReturns the status of whether this service will throw an error when encountering a problem.

Constructor Summary 

This class does not have a constructor, so you cannot create it directly.

Method Summary 

MethodDescription
call(Object…)Invokes the service.
getConfiguration()Returns the Service Configuration.
getCredentialID()Returns the ID of the currently associated Credential.
getRequestData()Returns the property that stores the object returned by createRequest.
getResponse()Returns the property that stores the object returned by the service.
getURL()Returns the current URL, excluding any custom query parameters.
isMock()Returns the status of whether this service is executing in mock mode.
isThrowOnError()Returns the status of whether this service will throw an error when encountering a problem.
setCredentialID(String)Override the Credential by the credential object with the given ID.
setMock()Forces the mock mode to be enabled.
setThrowOnError()Forces a Service to throw an error when there is a problem instead of returning a Result with non-OK status.
setURL(String)Override the URL to the given value.

Methods inherited from class Object 

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

Property Details 

URL 

URL: String

Returns the current URL, excluding any custom query parameters.


configuration 

configuration: ServiceConfig (read-only)

Returns the Service Configuration.


credentialID 

credentialID: String

Returns the ID of the currently associated Credential.


mock 

mock: Boolean

Returns the status of whether this service is executing in mock mode.


requestData 

requestData: Object (read-only)

Returns the property that stores the object returned by createRequest.


response 

response: Object (read-only)

Returns the property that stores the object returned by the service.

This property is only useful after the service call(Object...) completes, and is the same as the object inside the Result.


throwOnError 

throwOnError: Boolean

Returns the status of whether this service will throw an error when encountering a problem.


Method Details 

call(Object...) 

call(args: Object...): Result

Invokes the service.

Parameters:

  • args - Arguments to pass. If there is a single argument and that argument is an array, then each item in the array will become a separate argument. For example, the following results in three separate arguments to the service:
1svc.call( [1,2,3] )
1and is functionally equivalent to
1svc.call( 1, 2, 3 )
1This can be avoided by explicitly forming a [List](dw.util.List.md), enclosing the array in another             array, or by sending a second argument. The following will all send the array as a List in the first             argument.
1svc.call( ArrayList([1,2,3]) )
1svc.call( [[1,2,3]] )
1svc.call( [1,2,3], "" )
1Another option is to change the definition of the associated             [ServiceCallback.createRequest(Service, Object...)](dw.svc.ServiceCallback.md#createrequestservice-object) to accept an object instead, and pass the             array as a field of that object:
1svc.call( { 'data': [1,2,3] } )
1**Returns:**
2- Result of the service.

getConfiguration() 

getConfiguration(): ServiceConfig

Returns the Service Configuration.

Returns:

  • Service Configuration.

getCredentialID() 

getCredentialID(): String

Returns the ID of the currently associated Credential.

Returns:

  • Credential Name.

getRequestData() 

getRequestData(): Object

Returns the property that stores the object returned by createRequest.

Returns:

  • Object returned by createRequest.

getResponse() 

getResponse(): Object

Returns the property that stores the object returned by the service.

This property is only useful after the service call(Object...) completes, and is the same as the object inside the Result.

Returns:

  • Object returned by the service.

getURL() 

getURL(): String

Returns the current URL, excluding any custom query parameters.

Returns:

  • URL.

isMock() 

isMock(): Boolean

Returns the status of whether this service is executing in mock mode.

Returns:

  • true for mock mode, false otherwise.

isThrowOnError() 

isThrowOnError(): Boolean

Returns the status of whether this service will throw an error when encountering a problem.

Returns:

  • true to throw an error, false otherwise.

setCredentialID(String) 

setCredentialID(id: String): Service

Override the Credential by the credential object with the given ID.

If the URL is also overridden, that URL will continue to override the URL in this credential.

Parameters:

  • id - Credential ID. It must exist.

Returns:

  • this Service.

setMock() 

setMock(): Service

Forces the mock mode to be enabled.

Returns:

  • this Service.

setThrowOnError() 

setThrowOnError(): Service

Forces a Service to throw an error when there is a problem instead of returning a Result with non-OK status.

Returns:

  • this Service.

setURL(String) 

setURL(url: String): Service

Override the URL to the given value. Any query parameters (if applicable) will be appended to this URL.

Parameters:

  • url - Force the URL to the given value.

Returns:

  • this Service.