Edit links for module custom SQL queries

LabKey Support Forum (Inactive)
Edit links for module custom SQL queries Matt V  2017-04-25 13:34
Status: Closed
 
Within a module I have some custom queries, some use a .sql file. When managing basic datasets or those without SQL, there are links to edit existing rows. However, I'm not seeing a way to do that with my custom SQL. It is possible to insert new rows though.

Is it possible to re-add those edit links or otherwise build them myself in a way that LabKey will pick up?
 
 
Jon (LabKey DevOps) responded:  2017-04-26 17:29
Hi Matt,

Those links to edit rows are tied to tables (e.g. Lists & Datasets) rather than queries, which is why those edit links do not appear on queries.

For example, if you created a list (which would be your table) and then you created a query off of that list, the option to edit those records on the list wouldn't appear off of that query.

If you really need your query to have some kind of ability to do this, there is a hacky way to produce something like this. It would require you to leverage the URL feature within the metadata to accomplish this.

I created a very basic list called "ListTest" with three fields, the primary key, name, and "check" for a boolean value (see listscreenshot.png)

Then I created a query off of that list via the Schema Browser called "ListTest2":

SELECT 'Edit' AS Edit,
'Details' AS Details,
ListTest.Key,
ListTest.Name,
ListTest.Check
FROM ListTest

Then I added the following XML Metadata to the query.:

<tables xmlns="http://labkey.org/data/xml">
  <table tableName="ListTest2" tableDbType="NOT_IN_DB">
    <columns>
      <column columnName="Edit">
        <url>/query/updateQueryRow.view?schemaName=lists&amp;query.queryName=ListTest&amp;Key=${Key}</url>
      </column>
      <column columnName="Details">
        <url>/list/details.view?listId=1&amp;pk=${Key}</url>
      </column>
    </columns>
  </table>
</tables>

This created the Edit and Details links to the left of the record, even though it was a query. (See listqueryscreenshot.png)

Hope this helps.

Regards,

Jon