I found a simpler way, which is to use the very handy relatively new dynamic-handler feature. https://github.com/espocrm/documenta...mic-handler.md
I am using it to change field values on the fly for an entity called WorkOrder, see this code snippet below from my script client/custom/src/work-order-dynamic-handler.js.
The only drawback, in my case, because I am using enhanced dynamic logic to change the background color of the fields based on their values, is that in order for the changes to show up immediately a page reload is required but if you only want to change the value that will not be necessary.
Code:
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 page location.reload(); } } 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 page location.reload(); } } }
Leave a comment: