I am using save and close method in create.js to validate before save and it's working fine in create.js , how can i use the same code in record.js ?
I am using save and close method in create.js to validate before save and it's working fine in create.js , how can i use the same code in record.js ?
({ extendsFrom: 'CreateView', initialize: function (options) { this._super('initialize', [options]); }, saveAndClose: function () { var APIURL = "rest/v10/WPE_Work_Product_Enrollment?erased_fields=true&max_num=1&order_by=date_entered:desc"; var self = this; this._TestSysItem().then(function thenFunc(result) { console.log('termination_date_c out of api:',result); App.api.call("get", APIURL, null, { success: function (Data) { if(Data.records.length > 0) { var lastwp = Data.records[0].m03_work_product_wpe_work_product_enrollment_1_name; var lastStatus = Data.records[0].enrollment_status_c; if((lastwp!="APS001-AH01" && lastStatus =='On Study') || (result!='')) { app.alert.show("no_wpa_error", { level: "error", autoClose: true, messages: "New record can not create with this selection" }); } else { self.initiateSave(_.bind(function initSave() { if (self.closestComponent("drawer")) { app.drawer.close(self.context, self.model); } }, self)); } } } }); }.bind(this)); },
I extend the handleSave method in the record view controller.
see:
<your_sugar>/clients/base/views/record/record.js
If conditions are correct for the save then proceed to the save with the original save:
this._super('handleSave');
if conditions are not correct post an Alert message with details of the error, and then cancel with
this.handleCancel();
Better still, you could use field validation:
Note that this won't trigger if you are editing in list view, in a subpanel etc, you will need additional check in each of the controllers for those views.
This may get tricky and harder to maintain as records become editable from multiple views.
You might want to see if you can use constraints, I've not looked at this in detail:
Hope this helps,
FrancescaS