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.1 Script Basics and SuiteScript 2.1 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.1
 */
require(['N/action', 'N/util'], (action, util) => {
    // 1a) Execute the action for specified record IDs.
    const handle1a = 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' }
        ]
    });

    // Example search results: [1, 5, 23]
    const searchResults = [];

    // 1b) Generate distinct parameters programmatically.
    const handle1b = action.executeBulk({
        recordType: 'timebill',
        id: 'approve',
        params: searchResults.map((recordId) => ({
            recordId,
            note: `this is a note for ${recordId}`
        }))
    });

    // 2a) Execute using homogeneous parameters.
    const handle2a = action.executeBulk({
        recordType: 'timebill',
        id: 'approve',
        params: searchResults.map((recordId) => ({
            recordId,
            gold: 'bar',
            name: 'John Doe'
        }))
    });

    // 2b) Equivalent homogeneous-parameter example.
    const commonParams = {
        gold: 'bar',
        name: 'John Doe'
    };

    const handle2b = action.executeBulk({
        recordType: 'timebill',
        id: 'approve',
        params: searchResults.map((recordId) =>
            util.extend({ recordId }, commonParams)
        )
    });

    // 3) Execute with only record IDs.
    const handle3 = action.executeBulk({
        recordType: 'timebill',
        id: 'approve',
        params: searchResults.map((recordId) => ({ recordId }))
    });

    // 4) Execute on every qualifying record instance.
    const handle4 = action.executeBulk({
        recordType: 'timebill',
        id: 'approve',
        condition: action.ALL_QUALIFIED_INSTANCES,
        paramCallback: (recordId) => ({
            recordId,
            note: `this is a note for ${recordId}`
        })
    });

    // 5) Get the approve action for time bills.
    const approveTimebill = action.get({
        recordType: 'timebill',
        id: 'approve'
    });

    // 6) Execute the obtained action for specified record IDs.
    const handle6 = approveTimebill.executeBulk({
        params: searchResults.map((recordId) => ({
            recordId,
            note: `this is a note for ${recordId}`
        }))
    });

    // 7) Execute the obtained action on all qualifying records.
    const handle7 = approveTimebill.executeBulk({
        condition: action.ALL_QUALIFIED_INSTANCES,
        paramCallback: (recordId) => ({
            recordId,
            note: `this is a note for ${recordId}`
        })
    });

    // 8) Get the status of a bulk action execution.
    const res = action.getBulkStatus({
        taskId: handle7
    });

    log.debug({
        title: 'Bulk action status',
        details: res.status
    });
}); 

        

General Notices