Process Platform Ajax Plug-in |
The cordys.ajax plug-in is used to invoke the Process Platform Web services from a HTML page. It is an extension of the standard jQuery.ajax method with some additional parameters required for invoking Process Platform services. This plug-in handles the authentication, sending the requests to Process Platform and receiving the response after optional marshalling and unmarshalling to JSON.
Properties
The cordys.ajax plug-in takes the following properties from the options, which are passed as a parameter:
Table 1. List of Properties
Property |
Description |
---|---|
data |
Data to be sent to the server. This is a SOAP message, generated by the plug-in. The default behavior of the plug-in can be overwritten by setting this property to a string containing the complete message to be sent. |
dataFilter(data, type) |
Function used to handle the response data. This is a pre-filtering function to sanitize the response. This function accepts two arguments, the response data and the dataType parameter. This is a standard jQuery ajax setting. For more information on this function, refer to JQuery documentation. |
dataType |
Type of data returned from the server. This is set to xml by default. If you set it to json, this plug-in converts xml to json using a jQuery.ajax converter. |
error(jqXHR, textStatus, errorThrown) |
A function to be called in the case of a request failure. This plug-in handles the error by displaying an alert or redirecting to the login page when the AccessDenied error is encountered. You can specify your own error handler or set the property to null, if required. The function receives three arguments: the jQuery XMLHttpRequest object, a string describing the type of error that occurred, and an optional exception object. This is a standard jQuery ajax setting. Refer to JQuery documentation for more details on this property. |
iteratorSize |
Maximum number of objects to be returned. If this not set, it will retrieve all the possible objects. |
loginUrl |
URL of the login page. The default URL is /cordys/html5/mobilelogin.htm for a mobile Web page and /cordys/html5/login.htm for a normal Web page. You can specify another URL by setting this property. |
method |
Name of the method to be called |
namespace |
Namespace of the method to be called |
parameters |
Parameters of the method to be called. It can be any one of the following:
|
success(data, textStatus, jqXHR) |
Function to be called if the request succeeds. Three arguments are passed to the function: the data returned from the server, formatted according to the dataType parameter; a string describing the status; and the jQuery XMLHttpRequest object. This is a standard jQuery ajax setting. Refer to JQuery documentation for more details on this property. |
url |
URL to which the request is sent. The URL of the Process Platform Gateway is defined with the cookie information for authentication. |
Default Properties
Some properties have a default value set by the cordys.ajax plug-in:
Table 2. Default Properties
Property |
Default value |
Description |
---|---|---|
async |
true |
All the requests are sent asynchronously by default. If you need synchronous requests, set this option to false. |
contentType |
text/xml; charset=\"utf-8\" |
Type of content sent to the server |
dataType |
xml |
Type of data received from the server. You can set this property to json, if required. |
type |
POST |
Type of the request |
showLoadingIndicator | true |
Loading indicator is displayed by default. If you don't need the loading indicator, set this option to false. |
![]() |
If Jquery Mobile is available, default Jquery Mobile loading indicator will be displayed. Else, a custom loading indicator will be displayed. |
You can modify or add default properties by using the object $.cordys.ajax.defaults.
For example, to set the dataType of all the ajax requests from your page to json, you can do the following:
$.cordys.ajax.defaults.dataType = "json";
If the datatype is set as json and if the server response is of the type xml, it will be converted to the corresponding json object
Refer to the Rules on XML to JSON Conversion for more information.
Return value
The return value of any $.cordys.ajax call is a jQuery jqXHR object, which is Deferred compatible. On this object, you can call methods to obtain the status and define functions to be called on success or failure. For example, done(), fail(), and always().
Authentication
The cordys.authentication plug-in handles the authentication to connect to the Process Platform server. For more information, refer to Authenticating Users with HTML5 SDK.
Examples
The following are the the sample code snippets:
$.cordys.ajax({ method: "GetEmployeesObjects", namespace: "http://schemas.cordys.com/NW", parameters: { fromEmployeeID: "0", toEmployeeID: "99" }, dataType: 'json' }).done(function(employeesResponse) { // Show the employees on the screen }).fail(function(error) { alert("Error " + error + " in getting Employees"); });
$.cordys.ajax({ method: "GetTasks", namespace: "http://schemas.cordys.com/notification/workflow/1.0", parameters: { OrderBy:"Task.StartDate DESC" }, dataType: 'json' })
Note: You can also use the GetTasks method from the cordys.workflow plug-in.
$.cordys.ajax({ method: "GetBusinessIdentifierValues", namespace: "http://schemas.cordys.com/pim/queryinstancedata/1.0", dataType: 'json', parameters: { processInstanceID: selectedTask.ProcessInstanceId }, success: function(data) { // Sort the identifiers by Sequence var identifiers = data.tuple.sort(function(a, b) { return parseInt(a.old.BusinessIdentifier.Sequence) > parseInt(b.old.BusinessIdentifier.Sequence); }); // Put the identifiers in a separate array of objects that is part of a model bound to the html taskDetailModel.fields([]); $.each(identifiers, function(index, value) { taskDetailModel.fields.push({label:this.old.BusinessIdentifier.Description,value:this.old.BusinessIdentifier.Value}); }) } });
Note: You can also use the GetBusinessIdentifiers method from the cordys.process plug-in.