```function submitForApproval(recordId, employeeId...
# suitescript
k
Copy code
function submitForApproval(recordId, employeeId){

    try{

        var nextApprover;

        var workOrder = record.load({
            type: record.Type.WORK_ORDER,
            id: recordId
        })
        console.log("submitForApproval executed...");

        console.log(recordId);



        var employeeSearchObj = search.create({
            type: "employee",
            filters:
                [
                ],
            columns:
                [
                    search.createColumn({
                        name: "entityid",
                        sort: search.Sort.ASC,
                        label: "Name"
                    }),

                ]
        });
        var searchResultCount = employeeSearchObj.runPaged().count;
        log.debug("employeeSearchObj result count",searchResultCount);
        employeeSearchObj.run().each(function(result){
            // .run().each has a limit of 4,000 results
            if(result.id === employeeId){

                nextApprover = result.id;
            }
            return true;
        });


        workOrder.setValue({
            fieldId: "custbody_bbg_wo_approval_status",
            value: 1,
            ignoreFieldChange: true
        })

        workOrder.setValue({
            fieldId: "custbody_bb_next_approver_wo",
            value: nextApprover,
            ignoreFieldChange: true
        })

    }catch (e) {
        log.debug({title: "Error", details: e})
    }

}
e
Because you've loaded the record and then never saved it. Typically in a Client Script, you want to use
N/currentRecord
to work with the record in context, not
N/record
If
workOrder
is the record that the Client Script is deployed on, I'd switch to using
N/currentRecord
instead. Otherwise, you just need to call
workOrder.save()
within your function
m
So in client scripts you can use
console.debug
to help view stuff in your browser console or you can set breakpoints if your familiar with how to do that. Also I would recommend some changes. • filter on the
employeeId
so your search isn't returning so many results. Then you don't even need to analyze the results either. If your count is greater than 0 then set
nextApprover
to the
employeeId
. • Like @erictgrubaugh mentioned you are missing saving the work order, but it's more efficient to just do
record.submitFields
. https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4267283788.html#record.submitFields(options) when doing
record.load
it's 10 governance and
Record.save
is 20 governance.
record.submitFields
is only 10 governance.