Jam.py documentation

How to append a record using an edit form without opening a view form?ΒΆ

You must first call the open method of the item to initiate its dataset. For example, if you want to add a new record to invoices in the Demo application, you can do so as follows:

var invoices = task.invoices.copy();
invoices.open({ open_empty: true });
invoices.append_record();

In this code, we create a copy of the item using the copy method so that this operation does not affect the Invoices view form if it is open in a tab.

You can also change the record, but before you do this, you must get it from the server. Below is the code that modifies the record with id 411. We check that the record exists using the rec_count property, otherwise we display a warning.

var invoices = task.invoices.copy();
invoices.open({ where: {id: 411} });
if (invoices.rec_count) {
    invoices.edit_record();
}
else {
    invoices.alert_error('Invoices: record not found.');
}

In the example above the open method is not executed syncroniously.

The code below does it asyncroniously:

var invoices = task.invoices.copy();
invoices.open({ where: {id: 411} }, function() {
    if (invoices.rec_count) {
        invoices.edit_record();
    }
    else {
        invoices.alert_error('Invoices: record not found.');
    }
});

Invoices has the Modeless attribute set in the Edit form dialog, so the the edit form with be opened in a tab. You can change it by setting modeless attribute of edit_options to make the edit form modal:

var invoices = task.invoices.copy();
invoices.edit_options.modeless = false;