Hi all, was wondering if anyone knows a way to con...
# suitescript
t
Hi all, was wondering if anyone knows a way to conditionally include modules into a script. I have mocked up the following code
Copy code
define(['N/sftp', 'N/runtime', 'N/xml', 'N/encode', 'N/query', 'N/record', 'N/url', 'N/https'],
    (nsSftp, runtime, nsXml, nsEncode, nsQuery, nsRecord, nsUrl, nsHttps) => {

        let exports = {};

        function execute(context) {
            let filename = null;
            if (context?.type == 1) {
                filename = 'file1.js';
            } else if (context?.type == 2) {
                filename = 'file2.js';
            } else {
                filename = 'file3.js';
            }
            
            if (filename != null) {
                //option 1
                let includedFile = require(['/SuiteScripts/SuiteFunction/'+filename]);
                includeFile.Functionname(context);
                
                
                //option 2
                require(['/SuiteScripts/SuiteFunction/'+filename], (includedFile) => {
                    includeFile.Functionname(context);

                });
            }
        }

        exports.execute = execute;
        return exports;
    });
neither option 1 or option 2 work and was wondering if anyone had any idea how to make it work. Thanks in advance
j
I’ve totally done something similar to option 2 before, btw, and it worked
I’ve even used that technique to call SS2 from SS1
r
Use the
context.UserEventType
enum.
r
In the link you provided, they included
require
in their
define
statement:
define(['N/runtime', 'require'],
I do not see that in your sample code.