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
};
})
butterflyeffect Rookie Asked on January 25, 2021 in SuiteScript.
Add Comment
1 Answers

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.

Beginner Answered on January 25, 2021.

Thanks for your help , i tried to put this to load the record but still getting error

 var myrec = record.load({
                type: record.Type.SALES_ORDER,
                id: results[i] })
 
the err message:
“type”:”error.SuiteScriptError”,”name”:”SSS_MISSING_REQD_ARGUMENT”,”message”:”load: Missing a required argument: type”,”stack”:[“createError(N/error)”,”execute(/SuiteScripts/searchv2.js:13)”,”createError(N/error)”],”cause”:{“name”:”SSS_MISSING_REQD_ARGUMENT”,”message”:”load: Missing a required argument: type”},”id”:””,”notifyOff”:false,”userFacing”:true}
on January 26, 2021.

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
})

 

on January 26, 2021.

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
            });
           
        }
on March 30, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.