Execute a Bulk Action on a Timebill Record

The following sample shows how to execute a bulk approve action on a timebill record using different parameters.

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.

Important:

The following code samples do not serve as an order of execution, getBulkStatus should be executed later on and not right after the execution of action.executeBulk().

          /**
 * @NApiVersion 2.x
 */
require(['N/action', 'N/util']function(action, util) {

    // 1a) Bulk execute the specified action on a provided list of record IDs.
    // The params property is an array of parameter objects where each object contains required recordId and arbitrary additional parameters.
    var handle = action.executeBulk({
        recordType: "timebill",
        id: "approve",
        params: [{
                recordId: 1,
                note: "this is a note for 1"
            },
            {
                recordId: 5,
                note: "this is a note for 5"
            },
            {
                recordId: 23,
                note: "this is a note for 23"
            }
        ]
    })
});

// 1b) Bulk execute the specified action on a provided list of record IDs.
// The parameters in the previous sample are similar and can be generated programatically using the map function.
var searchResults = /* result of a search, for example, [1, 5, 23] */ ;
var handle = action.executeBulk({
    recordType: "timebill",
    id: "approve",
    params: searchResults.map(function(v) {
        return {
            recordId: v,
            note: "this is a note for " + v
        };
    })
});

// 2a) Bulk execute the specified action on a provided list of record IDs.
// This time with homogenous parameters, that is, all parameter objects are equal except recordId.
var handle = action.executeBulk({
    recordType: "timebill",
    id: "approve",
    params: searchResults.map(function(v) {
        return {
            recordId: v,
            foo: "bar",
            name: "John Doe"
        };
    })
});

// 2b) Bulk execute the specified action on a provided list of record IDs.
// This time with homogenous parameters. Equivalent to the previous sample.
var commonParams = {
    foo: "bar",
    name: "John Doe"
};
var handle = action.executeBulk({
    recordType: "timebill",
    id: "approve",
    params: searchResults.map(function(v) {
        return util.extend({
            recordId: v
        }, commonParams);
    })
});

// 3) Bulk execute the specified action on a provided list of record IDs.
// This is the simplest usage with no extra parameters besides the record ID.
var handle = action.executeBulk({
    recordType: "timebill",
    id: "approve",
    params: searchResults.map(function(v) {
        return {
            recordId: v
        }
    })
});

// 4) Bulk execute the specified action on all record instances that qualify.
// Since we don't have a list of recordIds in hand, we only provide the callback
// that will later be used to transform a recordId to the corresponding parameters object.
var handle = action.executeBulk({
    recordType: "timebill",
    id: "approve",
    condition: action.ALL_QUALIFIED_INSTANCES,
    paramCallback: function(v) {
        return {
            recordId: v,
            note: "this is a note for " + v
        };
    }
});

// 5) Get a particular action for a particular record type.
var approveTimebill = action.get({
    recordType: "timebill",
    id: "approve"
});

// 6) Bulk execute the previously obtained action on a provided list of record IDs.
// Params are generated the same way as above in action.executeBulk().
var handle = approveTimebill.executeBulk({
    params: searchResults.map(function(v) {
        return {
            recordId: v,
            note: "this is a note for " + v
        };
    })
});

// 7) Bulk execute the previously obtained action on all record instances that qualify.
var handle = approveTimebill.executeBulk({
    condition: action.ALL_QUALIFIED_INSTANCES,
    paramCallback: function(v) {
        return {
            recordId: v,
            note: "this is a note for " + v
        };
    }
});

// 8) Get status of a bulk action execution.
var res = action.getBulkStatus({
    taskId: handle
}); // returns a RecordActionTaskStatus object
log.debug(res.status);
}); 

        

General Notices