Workbook query assistance pls... First time workin...
# suitescript
m
Workbook query assistance pls... First time working with workbooks,.. Trying to load and return the results however getting error "{"type":"error.SuiteScriptError","name":"UNABLE_TO_LOAD_WORKBOOK","message":"Unable to load workbook: {1}","id":"","stack":["createError(N/error)","postProcess(/SuiteScripts/NetSuite Scripts/workbook.js:34)"],"cause":{"type":"internal error","code":"UNABLE_TO_LOAD_WORKBOOK","details":"Unable to load workbook: {1}","userEvent":null,"stackTrace":["createError(N/error)","postProcess(/SuiteScripts/NetSuite Scripts/workbook.js:34)"],"notifyOff":false},"notifyOff":false,"userFacing":false}" Request has "workbookID": and the ID of the workbook which is 30... Logs show:
Attempting to load workbook with ID: 30
Copy code
var log, workbook, response = new Object();

define(['N/log', 'N/workbook'], main);

function main(logModule, workbookModule) {
    log = logModule;
    workbook = workbookModule;

    return { post: postProcess };
}

function postProcess(request) {
    try {
        if (
            typeof request.workbookID === 'undefined' ||
            request.workbookID === null ||
            request.workbookID === ''
        ) {
            throw {
                type: 'error.WorkbookAPIError',
                name: 'INVALID_REQUEST',
                message: 'No workbookID was specified.',
            };
        }

        log.debug('Attempting to load workbook with ID: ' + request.workbookID);

        // Attempt to load workbook
        var myWorkbook;
        try {
            myWorkbook = workbook.load({
                id: request.workbookID
            });
        } catch (loadError) {
            log.error({
                title: 'Error loading workbook',
                details: loadError
            });
            throw {
                type: 'error.WorkbookLoadError',
                name: 'UNABLE_TO_LOAD_WORKBOOK',
                message: 'Unable to load workbook: ' + loadError.message
            };
        }

        var sheets = myWorkbook.getSheets();
        var allData = {};

        sheets.forEach(function (sheet) {
            var sheetName = sheet.getTitle();
            var data = sheet.getAllValues(); // Retrieve all data from the sheet
            allData[sheetName] = data;
        });

        response.results = allData;

        return response;
    } catch (e) {
        log.error({
            title: 'Script Error',
            details: e
        });
        return { error: { type: 'SCRIPT_ERROR', message: 'Error in script execution.' } };
    }
}
b
use the script id, not the internal id
it should begin with custworkbook as the prefix
m
it says unable to load dataset: {"type":"error.SuiteScriptError","name":"UNABLE_TO_LOAD_DATASET","message":"Unable to load dataset 'custdataset12'","id":"","stack": role has accss to workbooks and workbook dataset is shared w all? any idea what that would occur?
b
does the user/role have access to the dataset with the scriptid custdataset12
m
yep
what I'm slightly confused by is if the script is loading a custworkbook30, its then trying retrieve the dataset although nothing in the script suggests to load the dataset?
b
workbooks get their data from a dataset
om this case, hopefully custdataset12
login using the same user/role using the script
and find that dataset to make sure you actually have access