Documentation

BX24.callMethod

Use the following call to send a request.

XMLHttpRequest|XDomainRequest 
BX24.callMethod(
    String method,
    Object params[,
    Function callback]
);

The function calls a REST method with specified parameters. The parameters (the params object) are passed as an associative array which will be converted to a POST request string. The possible array values include strings or references to the DOM form elements (see processing files below).

If this method is called prior to calling BX24.init, the request will be queued and postponed.

Example

BX24.callMethod('user.get', 
                {ID: 10}, 
                function(res)
                {
                    if(res.data())
                    {
                        var user = res.data()[0];
                        if (!!user)
                            alert('The name of the user #' + user.ID + ' is ' + user.NAME);
                    }
                });

Attention! In Bitrix24 On-premise editions you can call REST methods using the method BX.rest.callMethod() instead of BX24.callMethod().


Processing the query result

The result request handler is a callback function called after the request has been completed; it accepts the following ajaxResult instance:

  • ajaxResult.prototype.data = function() - the function returning the REST method response as an array, an object or a scalar. Refer to the method descriptions for further information.
  • Boolean|String ajaxResult.prototype.error = function() - returns the error description if an error occurred, or false otherwise.

Some methods may return data of substantial size, in which case data is returned in chunks as consequential arrays of 50 items (methods may override this value). Use the following methods to navigate the data chunks:

  • Boolean ajaxResult.prototype.more = function() - returns true if there is still data to fetch. Applicable to methods that return data.
  • Integer ajaxResult.prototype.total = function() - returns the total number of data records. Applicable to methods that return data.
  • Boolean|XMLHttpRequest|XDomainRequest ajaxResult.prototype.next = function([Function cb]) - requests and returns the next data chunk. The default behavior is return data to the same callback function, which can be overridden by passing another callback function as the cb argument.

Example for searching users per page

BX24.callMethod('user.get', {sort:'ID',order:'ASC'}, function(result){
	if(result.error())
	{
		alert('Query error: ' + result.error());
	}
	else
	{
		console.log(result.data());
		if(result.more())
			result.next();
	}
});



© «Bitrix24», 2001-2024
Up