Creating views from queries via API

LabKey Support Forum
Creating views from queries via API millerjw4  2019-11-13 12:09
Status: Closed
 

Hello,

Currently we are using LabKey to connect to an external MSSQL data source. When the data source is connected, it gives the ability to view these tables via the built-in queries on the connected schema. However, I would like all of these views to be available for users of the project by default and not have to go in and manually create a Query Report based on each of the 100 or so queries.

Is there any way to insert these query report views into the labkey project programmatically?

Thanks,
Jonathan

 
 
Jon (LabKey DevOps) responded:  2019-11-29 17:02
Hi Jonathan,

You could try to leverage the LABKEY.Report API endpoint to try and insert in new Query Reports into the Data Views page.

https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.Report.html

However, it might be easier for you to just create a single wiki page that has some basic HTML with links that point to your external schema and tables.

If you look at your grid view for one of those tables on that external schema, you'll see the format of the URL containing the schemaName and queryName:

https://www.mylabkeyserver.com/MyProject/query-executeQuery.view?schemaName=MyExternalSchema&query.queryName=MyTable

If you have a list of those tables, you could build an HTML wiki with those tables as links and then use that wiki as a web part for users to access.

If you want to try to build this a little bit more programmatically, it is also possible to get a list of those tables from the Query API endpoint, which you can then extract those table/query names and build those same HTML links for your wiki.

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

Regards,

Jon