Call the REST service method with specified parameters BX24.callMethod
Sending a request
void BX24.callMethod(
String method,
Object params[,
Function callback
]
);
The method BX24.callMethod invokes the specified REST service method with the given parameters. The parameters of the method are represented by the params object, which is an associative array converted into a POST request string. The values of the array elements can be strings or references to DOM elements of form fields (see file uploads below).
If called before BX24.init, the request execution will be delayed.
Parameters
Required parameters are marked with *
|
Name |
Description |
|
method* |
The name of the REST API method to be called |
|
params |
Parameters passed to the method. Must match the expected parameters of the called method |
|
callback |
The callback function that will be executed after receiving a response from the server |
Example
BX24.init(() => {
BX24.callMethod('user.get', { ID: 10 }, (result) => {
if (result.error())
{
console.error(result.error());
}
else if (result.data())
{
const user = result.data()[0];
if (user)
{
alert('User №' + user.ID + ' is named ' + user.NAME);
}
}
});
});
How to Use Examples in Documentation
Warning
In on-premise versions, REST methods are called using the method BX.rest.callMethod(), not BX24.callMethod().
Handling the request result
The result handler of the request is a function. It receives an ajaxResult object, which provides the following methods:
data()— returns the response data of the method. The type of returned data can be an array, object, or scalar value, depending on the specific API methoderror()— returns an error object if an error is present, andundefinedotherwise. The error object contains the fieldsstatusandex, whereexincludeserroranderror_descriptionmore()— returnstrueif there is more data to load, andfalseotherwise. Applicable if the method returns a list of datatotal()— returns the total number of available records. Applicable if the method returns a list of datatime()— returns an object with information about the request execution time. It may returnundefinedif the information is unavailable.next(cb: Function)— requests the next page of data. If a functioncbis provided, it will be used as the result handler for the next request. Returnsfalseif there is no more data to load, or anXMLHttpRequestobject if the request was initiated.
Example of retrieving a paginated list of users
BX24.init(() => {
BX24.callMethod('user.get', { sort: 'ID', order: 'ASC' }, (result) => {
if (result.error())
{
alert('Request error: ' + result.error());
}
else
{
console.log(result.data());
if (result.more())
{
result.next();
}
}
});
});
How to Use Examples in Documentation
Continue your exploration
- Call the interface to register a new event handler callBind
- Call the interface to remove a registered event handler BX24.callUnbind
- Send a batch of requests with BX24.callBatch