When managing large volumes of Purchase Orders (POs), manually reviewing each one can be time-consuming and prone to oversight. As the number of transactions increases, it becomes harder to ensure that every PO is properly reviewed and documented.
This Admin Tip shows how you can streamline your workflow using a simple Scheduled Script that automatically identifies Pending Approval POs, applies a standardized review memo, and logs each update for easy tracking. By automating this repetitive task, you reduce the chances of missing critical reviews while improving accuracy and overall process efficiency.
Example Script
/**
* @NApiVersion 2 .x
* @NScriptType ScheduledScript
*/
define(['N/log', 'N/record', 'N/search'], function(log, record, search) {
function execute(context) {
log.audit({
title: 'PO Script Execution Started',
details: 'Beginning automated Purchase Order review.'
});
var poSearch = search.create({
type: search.Type.PURCHASE_ORDER,
filters: [['status', 'anyof', 'PurchOrd:A']], // Pending Approval
columns: ['tranid']
});
poSearch.run().each(function(result){
var poId = result.id;
try {
// Sample update, e.g., add a memo noting the review
record.submitFields({
type: record.Type.PURCHASE_ORDER,
id: poId,
values: { memo: 'PO reviewed by automation' }
});
log.audit({
title: 'PO Updated',
details: 'Purchase Order ' + result.getValue('tranid') + ' (Internal ID: ' + poId + ') marked as reviewed.'
});
} catch (e) {
log.audit({
title: 'PO Update Skipped',
details: 'Could not update PO ID ' + poId + ': ' + e.message
});
}
return true; // continue to next result
});
log.audit({
title: 'PO Script Execution Completed',
details: 'Automated review of Purchase Orders is finished.'
});
}
return { execute: execute };
});
1. Search for Pending Approval POs
The script uses a search.create() function to retrieve all Purchase Orders with status PurchOrd:A (Pending Approval).
2. Update Each PO Automatically
For every PO returned, it applies an update using record.submitFields()—in this case, adding a memo that indicates the PO has been reviewed by automation.
3. Log Audit Details for Traceability
Each step—start, individual PO updates, skipped records (due to errors), and completion—is logged using log.audit(). This is helpful when checking script execution logs, especially in production.
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!