我试图在Appian中编写一个定制的web,其中包括返回数据库表中行数的计数。为此,我在api代码中添加了这个局部变量。
local!countOfRows: a!queryEntity(
entity: cons!MY_DATABASE_TABLE_DS,
query: a!query(
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: -1
)
),
fetchTotalCount: true
).totalCount,我的想法是,然后将这个值作为输出之一包含在json中。例如:
local!dataBaseCasesWithDocs: {
numRecs: local!countOfRows,
recList: local!listOfRecords
}到目前为止,recList项工作得很好--从我的表中生成一个很好的json数据行列表,尽管每次10行。但是,当我使用countOfRows字段为numRecs添加代码时,该函数会出现错误500。
有什么想法吗?
增加额外的细节
我还尝试编写一个单独的api,它只返回实体的行计数,但它也返回错误500.
a!localVariables(
local!entities: a!queryEntity(
entity: cons!MY_DATABASE_TABLE_DS,
query: a!query(
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: -1
)
),
fetchTotalCount: true
).totalCount,
a!httpResponse(
headers: {
a!httpHeader(name: "Content-Type", value: "application/json")
},
body: a!toJson(value: local!entities)
)
)谢谢你,
大卫。
发布于 2020-01-29 07:35:41
with(
local!entities: a!queryEntity(
entity: cons!MY_DATABASE_TABLE_DS,
query: a!query(
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: 0
)
),
fetchTotalCount: true
).totalCount,
a!httpResponse(
headers: {
a!httpHeader(name: "Content-Type", value: "application/json")
},
body: a!toJson({count: local!entities})
)
)唯一的区别是我添加了10的批处理大小,但是它返回了数据库中正确的行数.
通过类似地将批处理大小更改为较小的数目而不是-1来检索所有记录,我也使原始代码工作。事实证明,检索所有记录对于获得这个totalCount字段的正确值并不是必要的:
local!countOfRows: a!queryEntity(
entity: cons!MY_DATABASE_TABLE_DS,
query: a!query(
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: 0
)
),
fetchTotalCount: true
).totalCount, 实际上,将此应用程序的批处理大小设置为0是最好的选择,因为这样可以获得元数据(包括totalCount),而不会浪费任何处理时间来检索数据行(在本例中没有使用)--从而提高了性能(感谢Mike提供了关于这一项的技巧)。
https://stackoverflow.com/questions/59960130
复制相似问题