In this section here, my Modal controller is outlined with Se_chnl and Se_segn_rqst as the Loopback models. The modal form is initialized in the first step, followed by fetching a list from the backend using $scope.Se_chnl_find() to populate a dropdown menu within the modal.
After filling out the form, the submit function is called which triggers the creation of a request using Se_segn_rqst.create($scope.rqst) where $scope.rqst holds the necessary parameters for the request creation.
However, the issue arises when attempting to retrieve the ID of the latest created request and store it in a global variable. Even though the record is successfully created in the backend, the find function does not return any data. Curiously, testing the find filter in Strongloop/Loopback explorer yields results while calling it from the controller doesn't.
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();
};
});
The key part that fails to return a value is highlighted above. My aim is to have an ID stored in the requested_id global variable after execution. While there seems to be no syntax error since the filter performs correctly in the Strongloop explorer, the discrepancy remains unresolved.
$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"
}
}
});