Scott Foster
03/17/2023, 1:50 PMLucas
03/17/2023, 5:01 PM/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
define(['N/search', 'N/runtime', 'N/record'], function(search, runtime, record) {
function execute(context) {
// Set the new owner's internal ID
var newOwnerId = '12345';
// Get the list of saved searches to update
var savedSearchList = getSavedSearchesToUpdate();
// Iterate through the saved searches and update the owner
for (var i = 0; i < savedSearchList.length; i++) {
try {
var savedSearchId = savedSearchList[i];
// Load the saved search record
var savedSearchRecord = record.load({
type: record.Type.SAVED_SEARCH,
id: savedSearchId
});
// Update the owner field with the new owner's internal ID
savedSearchRecord.setValue({
fieldId: 'owner',
value: newOwnerId
});
// Save the updated record
savedSearchRecord.save();
log.debug('Updated Saved Search', 'ID: ' + savedSearchId);
} catch (e) {
log.error('Error Updating Saved Search', 'ID: ' + savedSearchId + ' | Error: ' + e.message);
}
}
}
function getSavedSearchesToUpdate() {
// Replace this with the search criteria or the list of saved search IDs you want to update
var savedSearchList = [
'search_id_1',
'search_id_2',
// ...
];
return savedSearchList;
}
return {
execute: execute
};
});
Replace '12345' with the internal ID of the new owner and update the getSavedSearchesToUpdate() function to return the list of saved search IDs you want to update. Once you have updated the script, create a new Scheduled Script record in NetSuite and deploy it to run the script.Scott Foster
03/20/2023, 8:58 AM