Locate and Execute an Action on a Timebill Record

The following sample finds and executes an action on the timebill record without promises.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

          /**
 * @NApiVersion 2.x
 */
require(['N/action', 'N/record'], function(action, record) {
    // create timebill record  
    var rec = record.create({
        type: 'timebill',
        isDynamic: true
    });
    rec.setValue({
        fieldId: 'employee',
        value: 104
    });
    rec.setValue({
        fieldId: 'location',
        value: 312
    });
    rec.setValue({
        fieldId: 'hours',
        value: 5
    });
    var recordId = rec.save();

    var actions = action.find({
        recordType: 'timebill',
        recordId: recordId

    });

    log.debug("We've got the following actions: " + Object.keys(actions));
    if (actions.approve) {
        var result = actions.approve();
        log.debug("Timebill has been successfully approved");
    } else {
        log.debug("The timebill is already approved");
    }
});

// Outputs the following:
// We've got the following actions: approve, reject
// Timebill has been successfully approved 

        

General Notices