I am unable to fetch the List of Estimate records using SuiteScript in Netsuite. I have used the same script for the CUSTOMER records and it is working fine but when I am using the same for ESTIMATE records but it is not working.
Here is my SuiteScript code:
define(['N/https','N/query'], function (https, query) {
/**
* @NApiVersion 2.1
* @NScriptType WorkflowActionScript
*/
const exports = {};
function onAction(context)
{
// Create a query definition on estimate records
let myEstimateQuery = query.create({
type: query.Type.ESTIMATE
});
// Create conditions for the query
let firstCondition = myEstimateQuery.createCondition({
fieldId: 'Opportunity',
operator: query.Operator.EMPTY_NOT
});
myEstimateQuery.condition = myEstimateQuery.and(firstCondition);
// Create query columns
myEstimateQuery.columns = [
myEstimateQuery.createColumn({
fieldId: 'id'
}),
myEstimateQuery.createColumn({
fieldId: 'custbody_quote_internal_id'
}),
myEstimateQuery.createColumn({
fieldId: 'tranid'
}),
myEstimateQuery.createColumn({
fieldId: 'externalid'
}),
myEstimateQuery.createColumn({
fieldId: 'currency'
}),
myEstimateQuery.createColumn({
fieldId: 'duedate'
}),
myEstimateQuery.createColumn({
fieldId: 'enddate'
}),
myEstimateQuery.createColumn({
fieldId: 'startdate'
}),
myEstimateQuery.createColumn({
fieldId: 'subtotal'
}),
myEstimateQuery.createColumn({
fieldId: 'custbody_tran_term_in_months'
}),
myEstimateQuery.createColumn({
fieldId: 'custbody_end_user'
}),
myEstimateQuery.createColumn({
fieldId: 'custbody_qumu_deployment_type'
}),
myEstimateQuery.createColumn({
fieldId: 'custbody_qumu_orig_renewal'
}),
myEstimateQuery.createColumn({
fieldId: 'custbody_qumu_target_renewal'
})
];
// Run the query
let resultSet = myEstimateQuery.run();
log.debug('resultSet>> ', resultSet);
log.debug('resultSet.length>> ', resultSet.results.length);
log.debug('resultSet.results>> ', resultSet.results);
}
exports.onAction = onAction;
return exports;
});
There are a few issues you'll need to fix:
query.Type.ESTIMATEdoes not exist; you needquery.Type.TRANSACTIONas the Estimate/Quote record is a Transaction.recordtypeto get only Estimates.subtotalis not a valid query column. You can find the valid columns by looking up "transaction" in the Records Catalog underSetup > Records Catalog.FWIW if you happen to be more familiar with SQL, you can write this same query a bit more concisely using the
runSuiteQLmethod instead: