wcService.declare (initProperties)

The wcService.declare function declares a new AJAX service with the specified ID. In HCL Commerce, a service is a server URL that performs a server object create, update, delete, or other server processing. When needed, a Transaction server URL is called by using AJAX in the JavaScript code. When the service completes successfully, a JSON object that contain all the response properties of the URL request is returned to successHandler (the success response) or failureHandler (the failure response) defined JavaScript function. In addition, a WCTopic.publish is sent to any subscribed listeners if the service completes successfully. In this case, the WCTopic.subscribe events listening to the specified topic will be triggered.

Example

wcService.declare({
   id: "getCatalogEntryDetailsSA",
   actionId: "getCatalogEntryDetailsSA",
   url: getAbsoluteURL() + appendWcCommonRequestParameters("GetCatalogEntryDetailsByIDView"),
   formId: "",
   successHandler: function (serviceResponse, ioArgs) {
     shoppingActionsJS.displayPriceServiceResponse(serviceResponse, ioArgs);
   },   
   failureHandler: function (serviceResponse, ioArgs) {
      console.debug("ShoppingActions.changePrice: Unexpected error occurred during an xhrPost request.");
   }

});

Parameters

initProperties
(Object) Contains any of the initialization parameters.
id
(String) The unique ID of this service.
actionId
(String) An identifier for the action that is performed by this service. This value is used in the construction of the topic name for the model changed event. The model changed event name is in the following form: modelChanged/actionId.
url
(String) The URL for this service.
formId
(String) The ID of the form element that is posted to the URL. It is not necessary, however, to associate a service with a form element.
successHandler: function (serviceResponse)
Summary: Processes after a successful service invocation.
Description: This function is called after a successful service invocation to allow for any post-service processing. The default implementation does not perform any post-service processing. This function can be replaced by passing in a new version with the initProperties Object when the service is constructed.
serviceResponse: (Object) The service response object is the JSON Object returned by the service invocation.
failureHandler: function (serviceResponse)
Summary: Processes after a failed service invocation.
Description: This function is called after a failed service invocation to handle any error processing. The default implementation alerts the user with the error message found in the service response object. This function can be replaced by passing in a new version with the initProperties Object when the service is constructed.
serviceResponse: (Object) The service response object is the JSON Object returned by the service invocation.