JC
08/28/2025, 8:41 PMchristianRILECPQ
08/29/2025, 6:37 AMLuiz Morais
08/29/2025, 9:46 AMJC
08/29/2025, 12:11 PMLuiz Morais
08/29/2025, 12:34 PMrequire(['N/record','N/search', 'N/format'], function(record, search, format){
var wo = record.load({type: 'workorder', id: 75473579});
for(var i = 0; i < wo.getLineCount('item'); i++)
{
wo.setSublistValue('item', 'isclosed', i, true);
}
wo.save();
})JC
08/29/2025, 3:19 PMJC
08/29/2025, 3:27 PMLuiz Morais
08/29/2025, 3:28 PMJC
08/29/2025, 3:29 PM/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NAuthor J.C.
*/
define(['N/record', 'N/search', 'N/log'], function(record, search, log) {
function execute(context) {
// Replace 'saved_search_id' with the actual ID of your saved search
var savedSearchId = 'customsearchol_open_work_orders_3_4_2'; // Update with your saved search ID
var workOrderSearch = search.load({
id: savedSearchId
});
// Iterate through the search results
workOrderSearch.run().each(function(result) {
try {
// Get the internal ID of the work order from the search result
var workOrderId = result.id;
// Load the work order record
var wo = record.load({
type: 'workorder',
id: workOrderId,
isDynamic: false // Set to true if you prefer dynamic mode
});
// Get the line count of the 'item' sublist and set 'isclosed' to true
var lineCount = wo.getLineCount({ sublistId: 'item' });
for (var i = 0; i < lineCount; i++) {
wo.setSublistValue({
sublistId: 'item',
fieldId: 'isclosed',
line: i,
value: true
});
}
// Save the work order
wo.save({
ignoreMandatoryFields: false // Set to true if you want to bypass mandatory field validation
});
log.debug({
title: 'Work Order Updated',
details: 'Work Order ID: ' + workOrderId + ' updated successfully.'
});
} catch (e) {
log.error({
title: 'Error Processing Work Order',
details: 'Work Order ID: ' + workOrderId + ', Error: ' + e.message
});
}
// Continue processing the next result (return true to continue)
return true;
});
}
return {
execute: execute
};
});Andrew Altringer
09/25/2025, 11:35 PM