Scenario
Using the N/query module for filtering transaction line fields is returning error message: "Search error occurred: Field <id> for record 'transaction' was not found."
Incorrect sample code snippet
var tranQuery = query.create({
type: query.Type.TRANSACTION
});
tranQuery.columns = [
tranQuery.createColumn({fieldId: 'custcol8'}),
];
var resultSet = tranQuery.run();
Solution
This is because if you are planning to filter transaction lines, you have to prepend "transactionslines" before the transaction field id. As noticed in SuiteAnalytics, there is a separate table for transaction lines and it is highly likely that the N/query module is honoring this thus we have to prepend the transaction line table to introduce the transaction field id.
Correct sample code snippet:
var tranQuery = query.create({
type: query.Type.TRANSACTION
});
tranQuery.columns = [
tranQuery.createColumn({fieldId: 'transactionlines.custcol8'}),
];
var resultSet = tranQuery.run();