'file.load is returing "TypeError: Cannot call method "load" of undefined" on suitelet

Problem: I am trying to see if a file already exists in the file cabinet. If it does, the user gets a warning. If it does not, then the file proceeds to save. All components of these work except when I try to load the file I get the following error.

org.mozilla.javascript.EcmaError: TypeError: Cannot call method "load" of undefined (/SuiteScripts/suitelet_CheckIfFileExist.js#23)

I am currently passing a file id of a file I know exist for testing so I know that I am passing a valid file id.

ClientScript:

function checkIfFileExists(){
    CallforSuitelet_CheckIfFileExist();
    var result
    if(result == true){
        Ext.Msg.show({
        title:'Overwrite File?',
        msg: 'This existing file will be<br>overwritten:<br>' + msgBoxValue + '<br><br>Continue?',
                width: 300,
        icon: Ext.MessageBox.QUESTION,
        buttons: Ext.MessageBox.YESNO,
        fn: function(buttonId, value) {
            if (buttonId == 'yes') {
                CallforSuitelet();
                console.log('Yes pressed');
                } else {
                    Ext.Msg.show({
                    title:'Information',
                    msg: 'No files were copied.',
                    icon: Ext.MessageBox.INFO,
                    buttons: Ext.MessageBox.OK
                });
                    console.log('No pressed');
                    }
                    }
            });
        }
    }

 }
    
function CallforSuitelet_CheckIfFileExist(){
    console.log("CallforSuitelet_CheckIfFileExist function Entered")

var suiteletURL = url.resolveScript({
    scriptId:'customscript_suitelet_checkiffileexist',// script ID of your Suitelet 
    deploymentId: 'customdeploy_suitelet_checkiffileexist',//deployment ID of your Suitelet
    returnExternalURL: false,
    params: {
           'msgBoxValue':msgBoxValue
        }
    });
        console.log("suiteletURL = " + suiteletURL);

    https.get.promise({
            url: suiteletURL
            });
}

Suitelet:

   /**
    * @NApiVersion 2.x
    * @NScriptType Suitelet
    * @NModuleScope SameAccount
    */
   define(['N/file', 'N/log'],

   function(file, log) {

/**
 * Definition of the Suitelet script trigger point.
 *
 * @param {Object} context
 * @param {ServerRequest} context.request - Encapsulation of the incoming request
 * @param {ServerResponse} context.response - Encapsulation of the Suitelet response
 * @Since 2015.2
 */

function onRequest(context) {

    if (context.request.method === 'GET') {
        
        var requestParam = context.request.parameters;
        
        var fileName = 'Drag and Drop/Sales Order/' + requestParam.msgBoxValue + '.pdf';
        
        var contextResponse = 'true';
        
  
    function fileHasNoValue(fileId){
        if (typeof fileId == 'undefined'){
        return true;
        }
        if (fileId === null){
        return true;
        }
        if (fileId === ''){
        return true;
        }
    return false;
    }
    log.debug({details:'line beforefileOBj '})
    var fileObj = file.load(288784)
    //file.load({ <======= I have tried loading both ways
    //id: 288784
    //});

    try{
        var file = file.load({id: fileName});
        contextResponse = fileHasNoValue(file);
    } catch (e) {
        log.error({
        title: e.name,
        details: e.message});
        }
    };

  context.response.write(contextResponse)
  return;
}

return {
    onRequest: onRequest
};

});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source