I have a service that is connected to a MS Sql db. I use the getRecords() method on the API Docks page on my DSP, I pass a table name and a filter and receive the expected results. I then try passing the exact same getRecords query in my AngularJS App using the ngDreamFactory Module and I receive this 500 error: {“error”:[{“context”:null,“message”:“Failed to retrieve records from ‘VI_DF_GRD’.\nCDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 207 General SQL Server error: Check messages from the SQL Server [207] (severity 16) [(null)]”,“code”:500}]}. However, if I add the ids and id_field parameter I receive a 200ok response and a single record. Anyone have any similar problems or an idea of what would be causing the 500 error?
How do You set up Your DF? Are You waiting until it is ready? etc. Could You post some code? That would be the simplest way to let us help You.
I do wait until the DF Module is ready.
Here is my service:
myApp.service('CpTableService', function(DreamFactory) {
return {
// Define custom getRecords service
getRecords: function(params) {
// Call DreamFactory database service with params obj
// As long as we don't specify callback/error functions
// angular-dreamfactory will return promises which we are passing
// back as the result of the call to MyService.getRecords() in the controller
return DreamFactory.api.cp.getRecords(params);
}
}
});
This call to the service works:
$scope.loadOrders = function() {
// Params for call
var callParams = {
table_name: 'VI_DF_ORDERS',
ids: '149',
id_field: 'SLS_REP',
filter: 'AMT_DUE > 0 AND CUST_TYP ="C"',
fields: ['TKT_NO', 'TKT_DAT', 'SLS_REP', 'CUST_NO', 'AMT_DUE', 'DOC_STAT', 'NAM']
}
CpTableService.getRecords(callParams).then(
// Success function
function(result) {
// We have a returned promise here.
// your data will be wrapped in a data object.
// result.data.record
// Do something with the record set
$scope.orderData = result.data.record;
console.log($scope.orderData);
},
// Error function
function(reject) {
console.log(reject);
// Handle error
}
)
};
But this call returns a 500 error:
$scope.loadOrders = function() {
// Params for call
var callParams = {
table_name: 'VI_DF_ORDERS',
filter: 'SLS_REP = "149" AND AMT_DUE > 0 AND CUST_TYP ="C"',
fields: ['TKT_NO', 'TKT_DAT', 'SLS_REP', 'CUST_NO', 'AMT_DUE', 'DOC_STAT', 'NAM']
}
CpTableService.getRecords(callParams).then(
// Success function
function(result) {
// We have a returned promise here.
// your data will be wrapped in a data object.
// result.data.record
// Do something with the record set
$scope.orderData = result.data.record;
console.log($scope.orderData);
},
// Error function
function(reject) {
console.log(reject);
// Handle error
}
)
};
However, if I make this same call in the API Docs, it returns the requested records.
Can you provide the raw requests from the debugger for success and failure cases? That should help narrow it down.
I think I found the error…
filter: 'SLS_REP = "149" AND AMT_DUE > 0 AND CUST_TYP ="C"'
Dreamfactory does not like the double quotes when it receives the request parameters.
Reversing the quotes seems to have fixed the issue.
filter: "SLS_REP = '149' AND AMT_DUE > 0 AND CUST_TYP ='C'"
I am not sure if that is a bug or not, since you can usually use either single or double quotes in JavaScript.