Let’s assume that we have an item with a boolean field “posted”, and if the value of the field is true, we must prohibit changing or deleting the record.
We can do this by writing the on_after_scroll event handler and using permissions property:
function on_after_scroll(item) {
if (item.rec_count) {
item.permissions.can_edit = !item.posted.value;
item.permissions.can_delete = !item.posted.value;
if (item.view_form) {
item.view_form.find("#delete-btn").prop("disabled", item.posted.value);
}
}
}
In this event handler we check the value of the “posted” field and set the permissions property attributes to true.
We can also write the on_apply event handler in the server module of the item:
def on_apply(item, delta, params, connection):
for d in delta:
if d.posted.old_value:
raise Exception('Document posted. No change allowed')