I have some wiki pages that accept user input, and then save the inputted data to labkey study datasets using LABKEY.Query.insertRows. I seem to have a problem when I am saving data to more than one dataset. If the first insertRows is successful, I perform a second insertRows, and get the following 'ERROR: duplicate key value violates unique constraint "pk_participant"'. This happens most of the time, but every once in a while it works. Sometimes I'm trying to save one record to one dataset, and multiple records to a second dataset, and it saves at least one record for the second dataset before giving me the error. I'm stumped. Any ideas?
I'm using FireFox 4.0.
- Jen |
|
brittp responded: |
2011-04-21 09:43 |
Hi Jen,
This could be a product bug, but it's hard to say without more information. Would it be possible for you to post the JavaScript that you're using to insert the dataset rows? It would also be very helpful if you could attach the error log for your server. This file is called labkey-errors.log, and can be found in Tomcat's logs directory. If you used the Windows installer with default settings to set up LabKey Server, you can find this file here: C:\Program Files\LabKey Server\apache-tomcat-5.5.29\logs\labkey-errors.log
Thanks,
Britt |
|
jdutra responded: |
2011-04-21 10:33 |
Hi Britt,
I've attached the errorlog and the js code that causes my error. I'm saving one record to each of two different datasets. When I tried this to get the errorlog for you, my first submit worked, and successfully added a new participant to each of the two study datasets. The second time I got the error. That new participant was added to the Demographics dataset, but not Consent. Thanks for your help!
- Jen |
|
|
Ben Bimber responded: |
2011-04-21 10:46 |
hi jen,
i just glanced at this, and do you have the rest of the code that contains doSuccess, doNothing, etc? I'm not quite getting what those are doing.
thanks,
ben |
|
jdutra responded: |
2011-04-21 10:51 |
Hi Ben,
This is doSuccess:
function doSuccess() {
saveSuccess = true;
}
and doNothing doesn't do anything at all. The code is pretty simple, it's just trying to save to one dataset, and then, if the save was successful, save to a second dataset. All the functions you see in the insertRows are just getting the values I need from the form inputs, and I'm pretty sure there are no problems with any of them.
Thanks,
Jen |
|
Ben Bimber responded: |
2011-04-21 11:23 |
hi jen,
so i'm wondering if everything is executing in the proper order. successCallback from the first insertRows is going to be called asynchonously, so I wonder if often your second submitConsent function just isnt getting called. have a look at the attached modification. i made onSuccess from the first insertRows call the second one directly. i think seqNum should be in scope to both.
I didnt try any of this, so there may be typos.
-ben |
|
|
jdutra responded: |
2011-04-21 12:39 |
Ben,
I tried your fix, and it seems to be working at the moment. Trouble is, I'm pretty sure I had things set up that way initially in the other form that's causing this problem, and it still didn't work. But it's been awhile and I'll have to recheck it. In the meantime, thanks for your help!
- Jen |
|
brittp responded: |
2011-04-22 10:09 |
Hi Jen,
Ben's suggestions are good ones- his approach should make your code execute more consistently, and may fix your problem. That said, there does appear to be a product bug in that your original code was able to intermittently cause a server-side error. I've entered a bug in our issue tracker to address this problem:
https://www.labkey.org/issues/home/Developer/issues/details.view?issueId=12191
Please let us know if Ben's modifications aren't enough to get you up and running in the short term. And thanks, Ben, for jumping in and helping out!
Thanks,
Britt |
|
|
|