Use GetData API in file-based module

LabKey Support Forum
Use GetData API in file-based module Christopher Garay  2014-05-13 04:39
Status: Closed
 
The default JavaScript report code works well as an example:

var jsDiv;

// When a JavaScript report is viewed, LabKey calls the render() function, passing a query config
// and a div element. This sample code simply stashes the div, initializes callback functions, and
// calls selectRows() to retrieve the data from the server. See the "Help" tab for more details.
function render(queryConfig, div)
{
    jsDiv = div;
    queryConfig.success = onSuccess;
    queryConfig.error = onError;
    LABKEY.Query.GetData.getRawData(queryConfig);

    // If not using the GetData API you can use SelectRows instead:
    // LABKEY.Query.selectRows(queryConfig);
}

function onSuccess(results)
{
    //jsDiv.innerHTML = results.rows.length + ' rows returned';
}

function onError(errorInfo)
{
    jsDiv.innerHTML = errorInfo.exception;
}


If I open a new report (which has "Use GetData API" checked) and keep the example code I see the correct number of rows returned from the getRawData call. However, if I copy and paste this as a report file inside my module, keeping the call to getRawData yields the following error:

"Error: A source is required for a GetData request."

selectRows does return the correct number of rows when I use that in the file. It looks like LabKey is passing a different object for queryConfig that depends on whether or not the "Use GetData API" box being checked. It's unclear from the documentation how to enable this for a file-based module report in the module configuration.

Thanks for your help!

Chris