Matthew Bellew responded: |
2010-06-08 10:47 |
I want to look at this more carefully to see how the error handling works.
But I know it's common to reserve onError() for problems with the network or authentication, while onSuccess() handles the case where the server received/understood/responded to the request, regardless of whether the request generated an 'expected' error or not.
The json response should have an errors collection that indicates whether there were handled problems with the request.
I want to learn more about this anyway, so I'll look a little closer. |
|
Matthew Bellew responded: |
2010-06-08 13:32 |
I tried to reproduce this with a list and a required field. I found that my errorCallback was being called when a required field was not provided.
Can you elaborate on your scenario? Was it a list, dataset, etc... I'm guessing that you verified that the request worked when the required value was provided (e.g. no other problems)
matt |
|
Ben Bimber responded: |
2010-06-08 14:07 |
i was using the following. i originally used 'id' instead of 'employeeId' for my field name. correcting this fixed the problem and caused records to insert correctly. even with the incorrect name, the success function was still being called. it's a regular labkey list.
LABKEY.Query.insertRows({
containerPath: '/WNPRC/WNPRC_Units/Animal_Services/Compliance_Training/Private/EmployeeDB',
schemaName: 'lists',
queryName: 'CompletionDates',
scope: this,
rowDataArray: [{
RequirementName: 'SOP Review'
,EmployeeId: LABKEY.Security.currentUser.displayName
,Date: new Date().format("Y-m-d")
}],
successCallback: function(){
alert('Thank You for Reading Your SOPs. You have now completed your SOP requirements for the year.');
var url = LABKEY.ActionURL.buildURL(
'Project',
'begin.view',
'home'
);
window.location = url
},
failureCallback: function(errorInfo) {
Ext.Msg.alert("Error:", errorInfo);
}
});
} |
|
Matthew Bellew responded: |
2010-06-08 15:23 |
One problem is that insertRows() uses the errorCallback function not failureCallback. That might cause some confusion.
I see that the ClientAPI is not consistent about using errorCallback or failureCallback. We need to pick one and be consistent. |
|
Ben Bimber responded: |
2010-06-08 15:31 |
so that explains why failureCallbaback was not called; however, why was successCallback called? In that example, the alert would appear whether the record was actually inserted or not. |
|
Matthew Bellew responded: |
2010-06-08 15:55 |
OK, I think I have it. I reproduced what you described where the successCallback is being called. This is because the insert worked. The insert through the ListQueryUpdateService does not seem to correctly enforce the required property. I confirmed that updating through the ui (list/insert.view) does enforce it.
https://www.labkey.org/issues/home/Developer/issues/details.view?issueId=10401 |
|
Ben Bimber responded: |
2010-06-08 16:02 |
ok. so you are saying there's two layers to enforcement of the required property? because no record is being inserted in the example above as far as i can tell (assuming you misspell the field name). i presume means that something rejects it. |
|
Matthew Bellew responded: |
2010-06-09 09:08 |
Hmm, it's odd that you're not seeing the row inserted. Are you sure the grid you're using to view whether the row is inserted isn't filtered by the current user? |
|
Ben Bimber responded: |
2010-06-09 09:13 |
it's not filtered. that code snip should insert into a different list than the one on the page. it guess it's possible some completely different reason fails the import?
all i know is that on our production server, running 10.1, the above code snip inserts a row if the correct field names are supplied, but does not insert a row when the 'EmployeeId' field is listed as 'Id'. In either event successCallback is called. |
|
Matthew Bellew responded: |
2010-06-09 09:29 |
OK, I assumed you were running 10.2. I will try this against 10.1 and see what happens there. |
|
Matthew Bellew responded: |
2010-06-09 10:29 |
Are any of these fields the primary key field, or are you using an auto-increment primary key? |
|
Ben Bimber responded: |
2010-06-09 10:34 |
should be auto-incrementing. employeeId is a lookup to a different table for what it's worth. do you have an account on our server? |
|