Ever wanted to pull key details from all Purchase Orders in your account programmatically? This Scheduled Script gives you a quick and automated way to extract important information from Purchase Orders without having to manually open each one.
It’s especially useful for administrators or developers who need to monitor transactions, perform audits, or simply get a high-level summary of active or historical POs. With just a few lines of code, you can log the Internal ID, Vendor Name, Total Amount, and Status of each Purchase Order directly to your script logs—making it easier to analyze data or troubleshoot PO-related issues.
This Scheduled Script searches for mainline Purchase Orders and logs the following details:
- Internal ID (Record Identifier)
- Vendor Name (Entity)
- Total Amount
- Purchase Order Status
How It Works:
1.Search Setup:
- Searches for all mainline transactions of type PurchOrd (Purchase Orders).
- Retrieves columns: internalid, entity, total, status, and type.
2.Processing:
- For each result:
- Loads the transaction record by internal ID.
- Logs a summary including the Vendor name, Total, and Status.
3.Mapping Logic:
- Maps "PurchOrd" to record.Type.PURCHASE_ORDER to ensure correct record loading.
Example Log Output:
- Title: Transaction Loaded
- Details: ID: 1234 | Vendor Name: ABC Supplies | Total: 1,250.00 | Purch Status: pendingReceipt
Sample Scheduled Script (SuiteScript 2.x)
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
define(['N/search', 'N/record', 'N/log'], function(search, record, log) {
var TRANSACTION_MAPPING = {
"PurchOrd": record.Type.PURCHASE_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: "Vendor" }),
search.createColumn({ name: "total", label: "Total" }),
search.createColumn({ name: "status", label: "Status" }),
search.createColumn({ name: "type", label: "Type" })
]
});
txnSearch.run().each(function(result) {
var internalId = result.getValue({ name: "internalid" });
var vendorName = result.getText({ name: "entity" });
var total = result.getValue({ name: "total" });
var PurchStatus = result.getValue({ name: "status" });
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", "ID: " + internalId +
" | Vendor Name: " + vendorName +
" | Total: " + total +
" | Purch Status: " + PurchStatus);
} else {
log.error("Unmapped Type", "No mapping found for: " + typeCode);
}
return true;
});
}
return {
execute: execute
};
});
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!