RE: Cannot find function setValue in suite script 2.0?
hi all i wrote this scheduled script to un drop-off orders from saved search , but it gives me this error :
{Cannot find function setValue in object object Object}
i got the value from the saved search but trying to update the fields is not working the code is
/** * @NApiVersion 2.x * @NScriptType ScheduledScript */ define(['N/search','N/record', 'N/log'], function(search, record,log) { function execute() { var mySalesOrderSearch = search.load({ id: 'customsearch1199' }); var resultSet = mySalesOrderSearch.run(); var results = resultSet.getRange({ start: 0, end: 1000 }); for (var i = 0; i < results.length; i++) { printResults(results[i]); } function printResults(record) { log.debug({ title: "sales order id", details: results[i].id }); record.setValue({ fieldId: 'custbody_sor_dropoffstatus', value: 'NOT_STARTED' }).setValue({ fieldId: 'custbody_sor_dropoffqr', value: '' }).setValue({ fieldId: 'custbody_sor_dropoffimageurl', value: '' }).setValue({ fieldId: 'custbody_sor_dropoffstarttime', value: '' }).setValue({ fieldId: 'custbody_sor_dropoffarrivetime', value: '' }).setValue({ fieldId: 'custbody_sor_dropoffcompletetime', value: '' }); record.save({ enableSourcing: true, ignoreMandatoryFields: false });
} return true; } return { execute: execute }; })
record within the printResults() function is just a reference to a search row at the moment.
You need to load the sales order (around the log line) with record.load before you can set values, or use record.submitFields
I’d probably change the function input variable name to avoid confusion too.
Thanks for your help , i tried to put this to load the record but still getting error
Is the log.debug line recording the correct order IDs to the deployment log?
If so, try
var myrec = record.load({ type: record.Type.SALES_ORDER, id: results[i].id })
I would change the name of the printResults function parameter to avoid scope problems with the record module. Then I would load the record and start assigning the required values.
function printResults(pRecord) { log.debug({ title: "sales order id", details: pRecord.id }); let soRecord = record.load({type: pRecord.recordType, id: pRecord.id}) soRecord.setValue({ fieldId: 'custbody_sor_dropoffstatus', value: 'NOT_STARTED' }).setValue({ fieldId: 'custbody_sor_dropoffqr', value: '' }).setValue({ fieldId: 'custbody_sor_dropoffimageurl', value: '' }).setValue({ fieldId: 'custbody_sor_dropoffstarttime', value: '' }).setValue({ fieldId: 'custbody_sor_dropoffarrivetime', value: '' }).setValue({ fieldId: 'custbody_sor_dropoffcompletetime', value: '' }); soRecord.save({ enableSourcing: true, ignoreMandatoryFields: false });
}