Modules

filter

 

Objects/Functions

module (N/action)

SuiteScript 2.0

Main Examples

N/action Module
Member Type: Name
Search NetSuite - https://system.netsuite.com/app/help/helpcenter.nl?search=N/action Module

// Code Example 1
/**
* @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

// Code Example 2
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
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();

// find all qualified actions and then execute approve if available
action.find.promise({
recordType: 'timebill',
recordId: recordId
}).then(function(actions) {
console.log("We've got the following actions: " + Object.keys(actions));
if (actions.approve) {
actions.approve.promise().then(function(result) {
console.log("Timebill has been successfully approved");
});
} else {
console.log("The timebill is already approved");
}
});
});

// Outputs the following:
// We've got the following actions:
// The timebill has been successfully approved

// Code Example 3
/**
* @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 mandatory 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 very similar and can be generated programatically using the map function.
var searchResults = /* result of a search, e.g. [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, i.e. 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);
});

//SOURCE: https://system.netsuite.com/app/help/helpcenter.nl?fid=section_1510761537.html