我正在构建社区连接器并且在挠挠我的头;该文件指出:getData()中未定义的configParams调用
getData()
Returns the tabular data for the given request.
Request
@param {Object} request A JavaScript object containing the data request parameters.
The request parameter contains user provided values and additional information that can be used to complete the data request. It has the following structure:
{ "configParams": object, "scriptParams": { "sampleExtraction": boolean, "lastRefresh": string }, "dateRange": { "startDate": string, "endDate": string }, "fields": [ { object(Field) } ] }
我已经正确安装getConfig()(至少,我的配置是从用户的要求),但我的getData函数没有被通过的configParams对象。这是我的代码。
function getConfig(request) {
var Harvest = HarvestService({
token: getHarvestAuthService().getAccessToken()
});
var accounts = Harvest.accounts.list();
var options = accounts.map(function(account) {
return {
label: account.name,
value: account.id
};
});
var config = {
configParams: [
{
type: 'SELECT_SINGLE',
name: 'harvestAccountId',
displayName: 'Harvest Account ID',
helpText: 'The ID of the Harvest Account to pull data from.',
options: options
}
],
dateRangeRequired: true
};
return config;
}
function getData(request) {
var startDate = request.dateRange.startDate;
var endDate = request.dateRange.endDate;
var accountId = request.configParams.harvestAccountId;
var harvestAuthService = getHarvestAuthService();
var Harvest = HarvestService({
token: harvestAuthService.getAccessToken(),
account: accountId
});
var fieldKeys = request.fields.map(function(field) { return field.name; });
var entries = Harvest.entries.list({
startDate: new Date(startDate),
endDate: new Date(endDate)
});
var rows = entries.map(entryToRow);
return {
schema: request.fields,
rows: rows,
cachedData: false
};
}
当我测试/调试,我可以选择在配置步骤中的帐户,该模式是正确返回,但我得到以下情况例外,当我试图和小部件添加到报告:
Script error message: TypeError: Cannot read property "harvestAccountId" from undefined.
Script error cause: USER Script error stacktrace: getData:244
任何建议非常感谢。
感谢您的回答;问题是我的价值观不是字符串,他们不是在幕后强制。 –