NSDev
05/10/2021, 9:22 PMexport const getItemsByCategory = ({ categoryIds }) => {
return query.runSuiteQL({
query: `SELECT item.id, itemid as name
FROM item
WHERE custitem_category in (?)`,
params: categoryIds
}).asMappedResults()
}
categoryIds is an array of ids. When I pass in one id, it works, but when I pass in 2 ids:
getItemsByCategory({categoryIds:[224,155]})
I get this error:
message: 'Invalid number of parameters. Expected: 1. Provided: 2.',
object: {
type: 'error.SuiteScriptError',
name: 'INVALID_NUMBER_OF_PARAMETERS',
message: 'Invalid number of parameters. Expected: 1. Provided: 2.',
Can anyone help?battk
05/10/2021, 9:43 PMbattk
05/10/2021, 9:44 PMmichoel
05/11/2021, 12:44 AMexport const getItemsByCategory = ({ categoryIds }) => {
return query.runSuiteQL({
query: `SELECT item.id, itemid as name
FROM item
WHERE custitem_category in (${categoryIds.join(",")})`
}).asMappedResults()
}
Watz
05/11/2021, 9:44 AMgetItemsByCategory({categoryIds:['224,155']})
params accept an array of strings, numbers or booleans.
I believe each item in the array it mapped to each "?" in the order that they are entered in the SuiteQL.NSDev
05/11/2021, 1:57 PMWatz
05/11/2021, 2:51 PMNSDev
05/11/2021, 3:24 PMmichoel
05/12/2021, 12:00 AMconst sanitizedCategoryIds = sanitizedCategoryIds.map((e) => Number(e));
.
But thinking this through, probably the best option would be to use multiple placeholders:
export const getItemsByCategory = ({ categoryIds }) => {
return query.runSuiteQL({
query: `SELECT item.id, itemid as name
FROM item
WHERE custitem_category in (${categoryIds.map((e) => "?").join(",")})``,
params: categoryIds
}).asMappedResults()
}
Watz
05/12/2021, 5:45 AMNSDev
05/12/2021, 2:26 PM