Documentation

BX24.callBatch

It is not uncommon for an application to send requests in series. For example, an application may need to create entities while installing itself. Use this function to batch call REST methods instead of sending requests one by one.

void BX24.callBatch(
    Object|Array calls,
    [Function callback[,
    Boolean bHaltOnError = false]]
);

If this method is called prior to calling BX24.init, the requests will be queued and sent once the library is initialized.

The method sends multiple consecutive requests to the REST service.

Parameters

Parameter Description
calls

A simple or associative array containing requests to be sent.

Each of the requests can be either an array [method_name, method_parameters], or an object {method: method_name, params: method_parameters}.

The method parameters can include macros to access the results of the previous calls in the batch. Use the following syntax to create macros: $result[request_ID][return_field], here request_ID is the calls array key.

callback A user defined callback function that processes the batch call results. The function accepts an array (or an object) ajaxResult containing the results of the calls; the result array keys are the same as specified in the calls array.
bHaltOnError If true, the batch will be aborted if an error occurs. Otherwise, all the requests will be passed to REST service.

Example

BBX24.callBatch({
        get_user: ['user.current', {}],
        get_department: {
            method: 'department.get',
            params: {
                ID: '$result[get_user][UF_DEPARTMENT]'
            }
        }
}, function(result)
    {
        var l = result.get_department.data().length;
        var str = 'The current user ' + result.get_user.data().NAME + ' ' + 
                                        result.get_user.data().LAST_NAME + 
                                        ' belongs to the following department' + 
                                        (l > 1 ? 's ' : ' ');

        for (var i = 0; i < l; i++)
        {
            str += i == 0 ? '' : ', ';
            str += result.get_department.data()[i].NAME;
        }

        alert(str);
    }
);

See Also



User Comments

User comments are not part of official documentation. Use information provided by other users in the comments at your own risk.

The User Comments section is not to be used as a feature discussion board. Only registered users can post comments. Your comment will be visible once it has been approved by the moderator.
© «Bitrix Inc.», 2001-2019, «Bitrix Inc.», 2019