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



© «Bitrix24», 2001-2024
Up