Hi all, is it possible to update saved search owne...
# suitescript
s
Hi all, is it possible to update saved search owners using script? I have 209 searches to shift to a new owner 😕 edit: I've tried a map/reduce script which runs okay but doesn't set the owner field.
l
Can you try SS? @Scott Foster
Copy code
/**
 * @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.
s
@Lucas thanks mate, I've tried ChatGPT4 already and it doesn't work. I did some more digging and it looks like Saved Search is not exposed to SS.