As a NetSuite Administrator, there are times when you need to monitor or audit specific Transactions in the system, such as Sales Orders. This can help ensure accuracy, trace issues, or simply understand how data flows through your account. One efficient way to do this is by using a Scheduled Script to automate the process of identifying and logging key transaction details.
This article demonstrates how to use a Scheduled Script to search for mainline Sales Orders, load each one, and log critical details like Internal ID, Transaction Type, and Customer Name.
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
/**
* This script searches for mainline Sales Orders, maps their transaction type
* to the correct NetSuite record.Type, and loads each transaction record.
* It logs the internal ID, type, and customer name of each loaded transaction.
*/
define(['N/search', 'N/record', 'N/log'], function(search, record, log) {
var TRANSACTION_MAPPING = {
"SalesOrd": record.Type.SALES_ORDER
};
function execute(context) {
var txnSearch = search.create({
type: search.Type.TRANSACTION,
filters: [
["type", "anyof", Object.keys(TRANSACTION_MAPPING)],
"AND",
["mainline", "is", "T"]
],
columns: [
search.createColumn({ name: "internalid", label: "Internal ID" }),
search.createColumn({ name: "entity", label: "Customer" }),
search.createColumn({ name: "type", label: "Type" })
]
});
txnSearch.run().each(function(result) {
var internalId = result.getValue({ name: "internalid" });
var customerName = result.getText({ name: "entity" });
var typeCode = result.getValue({ name: "type" });
var recordType = TRANSACTION_MAPPING[typeCode];
if (recordType) {
var txnRecord = record.load({
type: recordType,
id: internalId
});
log.debug("Transaction Loaded", "Type: " + typeCode + " | ID: " + internalId + " | Customer: " + customerName);
} else {
log.error("Unmapped Type", "No mapping found for: " + typeCode);
}
return true;
});
}
return {
execute: execute
};
});
- This script only logs mainline Sales Orders. You can expand the TRANSACTION_MAPPING object to include other types like CustInvc (Invoice), CashSale, etc.
- It uses the search.Type.TRANSACTION search to retrieve multiple types of transactions, but filters for those you want.
- Make sure to deploy this Scheduled Script with appropriate execution time and deployment status in the script record.
The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
To know more about deploying SuiteScript, check these New to NetSuite Articles.
Do you have another way on how to automate your transactions using SuiteScript? Feel free to share them here!