To generate a script for a given dataset:
For example, the Physical Exam dataset in the LabKey Demo Study can be retrieved using this snippet of JavaScript:
<script type="text/javascript" nonce="<%=scriptNonce%>">
LABKEY.Query.selectRows({
requiredVersion: 9.1,
schemaName: 'study',
queryName: 'Physical Exam',
columns: 'ParticipantId,date,Weight_kg,Temp_C,SystolicBloodPressure,DiastolicBloodPressure,Pulse,Signature,Pregnancy,Language,ARV,height_cm,DataSets/Demographics/Group',
filterArray: null,
success: onSuccess,
failure: onError
});
function onSuccess(results) {
var data = '';
var length = Math.min(10, results.rows.length);
// Display first 10 rows in a popup dialog
for (var idxRow = 0; idxRow < length; idxRow++) {
var row = results.rows[idxRow];
for (var col in row) {
data = data + row[col].value + ' ';
}
data = data + 'n';
}
alert(data);
}
function onError(errorInfo) {
alert(errorInfo.exception);
}
</script>
Filters. Filters that have been applied to the grid view are included in the script. Note that some module actions apply special filters to the data (e.g., an assay may filter based on a "run" parameter in the URL); these filters are not included in the exported script. Always test the generated script to verify it will retrieve the data you expect, and modify the filter parameters as appropriate.
Column List. The script explicitly includes a column list so the column names are obvious and easily usable in the code.
Foreign Tables. The name for a lookup column will be the name of the column in the base table, which will return the raw foreign key value. If you want a column from the foreign table, you need to include that explicitly in your view before generating the script, or add "/<ft-column-name>" to the field key.
JavaScript Examples.
previousnext |
expand allcollapse all |