copy

copy(options)

domain: client

language: javascript

class Item class

Description

Use copy to create a copy of an item. The created copy is not added to the task tree and will be destroyed by JavaScript garbage collection process when no longer needed.

All attributes of the copy object are defined as they were at the time of loading of the task tree when application started. See Workflow

Options parameter further specifies the created copy. It can have the following attributes:

  • handlers - if the value of this attribute is true, all the settings to the item made in the Form Dialogs in the Application Builder and all the functions and events defined in the client module of the item will also be available in the copy. The default value is true.

  • filters - if the value of this attribute is true, the filters will be created for the copy, otherwise there will be no filters. The default value is true.

  • details - if the value of this attribute is true, the details will be created for the copy, otherwise there will be no details. The default value is true.

Example

The following code is used in the Demo project to asynchronously calculate total values of the fields, displayed at the foot of the Invoice journal table:

function on_filter_applied(item) {
    var copy = item.copy({handlers: false, details: false});
    copy.assign_filters(item);
    copy.open(
        {fields: ['subtotal', 'tax', 'total'],
        funcs: {subtotal: 'sum', tax: 'sum', total: 'sum'}},
        function() {
            var footer = item.view_form.find('.dbtable.' + item.item_name + ' tfoot');
            copy.each_field(function(f) {
                footer.find('div.' + f.field_name)
                    .css('text-align', 'right')
                    .css('color', 'black')
                    .text(f.display_text);
            });
        }
    );
}

See also

Task tree

Workflow