Below is my Modal controller. Se_chnl and Se_segn_rqst are the Loopback models. I'm initializing the modal form in the first step. The $scope.Se_chnl_find() is getting me a list from the backend which I load as a dropdown menu in the modal. This call to loopback works fine.
Then later on once the form is filled, I call the submit function and in that I call the create function of loopback Se_segn_rqst.create($scope.rqst) $scope.rqst contains the parameters for creating that rqst.
Now, once I have created this "rqst", I want to retrieve ID of the latest created request by that user and store it in the global variable. But the loopback api/MySQL doesn't return anything. Record is created in the backend when create is used. But the find function doesn't work.
I tried the find filter in Strongloop/Loopback explorer and it works there. Not sure why it is not returning anything when I tried it from the controller.
codeApp.controller('ModalInstanceCtrl', function($scope, $modalInstance, $state, Se_chnl, Se_segn_rqst) {
var defaultForm = {
cmpgn_nm: "",
cmpgn_id: "",
strgy_id: "",
rqst_typ_cd: "",
chnl_id: ""
}
$scope.channels = Se_chnl.find({
filter: {
"fields": {
"chnl_nm": true,
"chnl_id": true
}
}
});
$scope.rqst = angular.copy(defaultForm);
$scope.rqst.rqst_id = 0;
$scope.submit = function(reqForm) {
$scope.rqst.rqst_nm = $scope.rqst.cmpgn_nm;
$scope.rqst.rqst_stat_cd = 'DRAFT';
$scope.rqst.insrt_user_id = $scope.$parent.user_id;
$scope.rqst.insrt_dt = new Date();
Se_segn_rqst.create($scope.rqst);
$scope.$parent.requested_id = Se_segn_rqst.find({
filter: {
"fields": {
"rqst_id": true
},
"order": "insrt_dt DESC",
"limit": 1,
"where": {
"rqst_stat_cd": "DRAFT",
"insrt_user_id": "xyz123"
}
}
});
$modalInstance.dismiss('cancel');
};
$scope.resetForm = function(reqForm) {
$scope.rqst = angular.copy(defaultForm);
reqForm.$setPristine();
reqForm.$setUntouched();
};
});This is the piece returning no value. I want an id in the requested_id global variable. The filter is performing correctly in the Strongloop explorer, so there is no syntax error.
$scope.$parent.requested_id = Se_segn_rqst.find({
filter: {
"fields": {
"rqst_id": true
},
"order": "insrt_dt DESC",
"limit": 1,
"where": {
"rqst_stat_cd": "DRAFT",
"insrt_user_id": "xyz123"
}
}
});{ "name": "se_segn_rqst", "base": "PersistedModel", "idInjection": false, "options": { "validateUpsert": true }, "mysql": { "schema": "segtool", "table": "se_segn_rqst" }, "properties": { "rqst_id": { "type": "Number", "id": true, "required": true, "length": null, "precision": 10, "scale": 0, "mysql": { "columnName": "RQST_ID", "dataType": "int", "dataLength": null, "dataPrecision": 10, "dataScale": 0, "nullable": "N" }, "_selectable": false }, "rqst_nm": { "type": "String", "required": false, "length": 50, "precision": null, "scale": null, "mysql": { "columnName": "RQST_NM", "dataType": "varchar", "dataLength": 50, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "rqst_stat_cd": { "type": "String", "required": false, "length": 50, "precision": null, "scale": null, "mysql": { "columnName": "RQST_STAT_CD", "dataType": "varchar", "dataLength": 50, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "chnl_id": { "type": "Number", "required": false, "length": null, "precision": 10, "scale": 0, "mysql": { "columnName": "CHNL_ID", "dataType": "int", "dataLength": null, "dataPrecision": 10, "dataScale": 0, "nullable": "Y" }, "_selectable": true }, "strgy_id": { "type": "String", "required": false, "length": 50, "precision": null, "scale": null, "mysql": { "columnName": "STRGY_ID", "dataType": "varchar", "dataLength": 50, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "cmpgn_id": { "type": "String", "required": false, "length": 30, "precision": null, "scale": null, "mysql": { "columnName": "CMPGN_ID", "dataType": "varchar", "dataLength": 30, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "cmpgn_nm": { "type": "String", "required": false, "length": 50, "precision": null, "scale": null, "mysql": { "columnName": "CMPGN_NM", "dataType": "varchar", "dataLength": 50, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "prvcy_mail_ind": { "type": "Boolean", "required": false, "length": 1, "precision": null, "scale": null, "mysql": { "columnName": "PRVCY_MAIL_IND", "dataType": "char", "dataLength": 1, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "prvcy_phone_ind": { "type": "Boolean", "required": false, "length": 1, "precision": null, "scale": null, "mysql": { "columnName": "PRVCY_PHONE_IND", "dataType": "char", "dataLength": 1, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "prvcy_fcra_ind": { "type": "Boolean", "required": false, "length": 1, "precision": null, "scale": null, "mysql": { "columnName": "PRVCY_FCRA_IND", "dataType": "char", "dataLength": 1, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "prvcy_glb_ind": { "type": "Boolean", "required": false, "length": 1, "precision": null, "scale": null, "mysql": { "columnName": "PRVCY_GLB_IND", "dataType": "char", "dataLength": 1, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "prvcy_piped_ind": { "type": "Boolean", "required": false, "length": 1, "precision": null, "scale": null, "mysql": { "columnName": "PRVCY_PIPED_IND", "dataType": "char", "dataLength": 1, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "prvcy_facta_ind": { "type": "Boolean", "required": false, "length": 1, "precision": null, "scale": null, "mysql": { "columnName": "PRVCY_FACTA_IND", "dataType": "char", "dataLength": 1, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "prvcy_swpstk_ind": { "type": "Boolean", "required": false, "length": 1, "precision": null, "scale": null, "mysql": { "columnName": "PRVCY_SWPSTK_IND", "dataType": "char", "dataLength": 1, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "prev_rqst_id": { "type": "String", "required": false, "length": 30, "precision": null, "scale": null, "mysql": { "columnName": "PREV_RQST_ID", "dataType": "varchar", "dataLength": 30, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "rqst_typ_cd": { "type": "String", "required": false, "length": 30, "precision": null, "scale": null, "mysql": { "columnName": "RQST_TYP_CD", "dataType": "varchar", "dataLength": 30, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "insrt_dt": { "type": "Date", "required": false, "length": null, "precision": null, "scale": null, "mysql": { "columnName": "INSRT_DT", "dataType": "date", "dataLength": null, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "insrt_user_id": { "type": "String", "required": false, "length": 10, "precision": null, "scale": null, "mysql": { "columnName": "INSRT_USER_ID", "dataType": "varchar", "dataLength": 10, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "upd_dt": { "type": "Date", "required": false, "length": null, "precision": null, "scale": null, "mysql": { "columnName": "UPD_DT", "dataType": "date", "dataLength": null, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "upd_user_id": { "type": "String", "required": false, "length": 10, "precision": null, "scale": null, "mysql": { "columnName": "UPD_USER_ID", "dataType": "varchar", "dataLength": 10, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true }, "prvcy_email_ind": { "type": "String", "required": false, "length": 30, "precision": null, "scale": null, "mysql": { "columnName": "PRVCY_EMAIL_IND", "dataType": "varchar", "dataLength": 30, "dataPrecision": null, "dataScale": null, "nullable": "Y" }, "_selectable": true } }, "validations": [], "relations": { "se_segn_rqst_popn": { "type": "hasMany", "model": "se_segn_rqst_popn", "foreignKey": "rqst_id" }, "se_segn_rqst_excln": { "type": "hasMany", "model": "se_segn_rqst_excln", "foreignKey": "rqst_id" }, "se_chnl": { "type": "belongsTo", "model": "se_chnl", "foreignKey": "chnl_id" } }, "acls": [], "methods": []}
...