INSERT INTO using the webinterface

LabKey Support Forum (Inactive)
INSERT INTO using the webinterface volker  2013-05-30 03:22
Status: Closed
 
We are using Labkey 12.2 and I would like to set up a study template for users without SLQ or Java knowledge.

One thing we would like to have is, if users enter the Personal Identification Number (PID) in the participant dataset, all other datasets automatically insert a new row using this PID.

To insert data from one table into another one I can use the INSERT INTO command and refer via SELECT and FROM to the data. SQL code would be something like:

INSERT INTO Table2
 (client_last_name, client_first_name, taskDescription, category)
 (SELECT clientLastName, clientFirstName, incidentDescription, category
  FROM Table1)

How can I do this using the webinterface ?
Via lookup the existing PID numbers are shown in a drop down list for the according field, but I did not find a way to do a lookup without programming it.

Any help, suggestions, etc. appreciated.

Thanks,
Volker
 
 
jeckels responded:  2013-05-30 17:04
Hi Volker,

I'd recommend using a trigger script on your demographics dataset to hook this up:

https://www.labkey.org/wiki/home/Documentation/page.view?name=serverSideValidation

In your beforeInsert() function, you can use LABKEY.Query.insertRows() to insert blank rows into all of the other datasets:

https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.Query.html#.insertRows

You can use LABKEY.Query.selectRows() to ask the "dataset" query in the "study" schema what datasets are available if you don't want to have the set hard-coded in your trigger script. Note that for non-demographic datasets, you'll need to include the PID as well as a date/visit number. Non-demographic datasets always require a date or visit number (which one depends on the type of study you've created) as part of every row.

https://www.labkey.org/wiki/home/Documentation/page.view?name=setupDatasets

Thanks,
Josh
 
volker responded:  2013-06-04 22:25
Hi Josh,

I think the trigger script is the way to go, thanks for your quick response.

Best regards,
Volker