Yes you can do this through the dynamic handler class https://docs.espocrm.com/development/dynamic-handler/
Here's the code that we use to make changes to a WorkOrder entity enum options based on certain constrains, I think it is similar to your use case so hopefully it will show you how you can implement your solution.
Code:
define('custom:work-order-dynamic-handler', ['dynamic-handler'], function (Dep) {
return Dep.extend({
init: function () {
this.controlFields();
// invoke controlFields methods every time status or serviceTechId get changed
this.recordView.listenTo(this.model, 'change:status', this.statusControlField.bind(this));
this.recordView.listenTo(this.model, 'change:serviceTechId', this.serviceTechIdControlField.bind(this));
},
controlFields: function () {
this.statusControlField();
this.serviceTechIdControlField();
},
statusControlField: function () {
// limit the choices for status if the Service Tech field is empty
if (!this.model.get('serviceTechId')) {
this.recordView.setFieldOptionList('status', [
'Unassigned',
'Canceled'
]);
}
},
serviceTechIdControlField: function () {
// limit the choices for status if the Service Tech field is not empty
if (this.model.get('serviceTechId')) {
this.recordView.setFieldOptionList('status', [
'Assigned',
'Completed',
'Canceled'
]);
// if a Service Tech has been selected, and the status was Unassigned, change the status to "Assigned"
if(this.model.get('status') === 'Unassigned') {
this.model.set('status','Assigned');
// persist the change
this.model.save();
// refresh the display
this.model.fetch();
}
} else {
// if the Service Tech is erased and the status is Assigned, change it to "Unassigned"
if(this.model.get('status') === 'Assigned') {
this.model.set('status','Unassigned');
// persist the change
this.model.save();
// refresh the display
this.model.fetch();
}
}
}
});
});

Leave a comment: