0
votes

The following script is deployed and runs correctly:

/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define([],

function() {
    const lineFieldLookup = [
      'custcol_sas_adapter', 'custcol_sas_body', 'custcol_sas_box', 'custcol_sas_endcap',
      'custcol_sas_lidcap', 'custcol_sas_mortrclr', 'custcol_sas_snout', 'custcol_sas_strmclr',
      'custcol_sas_topclamp', 'custcol_sas_tplate'];

      function validateLine(scriptContext) {
           const fieldValuesTable = lineFieldLookup.map((fieldId) => {
             return ({
               fieldId: fieldId,
               value: scriptContext.currentRecord.getCurrentSublistValue({sublistId:'item', fieldId: fieldId })
             })
           });
        console.log(fieldValuesTable)
    }

    return {
       validateLine: validateLine,
    };
});

However, adding 'N/search' dependency to the script via browser 'edit' and clicking save throws an error.

Updated Code:

define(['N/search'],

function(search) {
  // nothing changed here
}

The error:

Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"","stack":[]}

What's preventing me from being able to add the search dependency?

1
I'd open a support case with NS for this. I'm experiencing the same issue in my account and I've seen others talk about this issue in NetSuite Professionals Slack - Mike Robbins
I had the same issue and this worked for me: edit script changing "2.1" to "2.0" or "2.x", add the modules you want, save script, edit script changing back to "2.1". Not sure why; but I was glad that it did. :) - Martha
@Martha unfortunately, that didn't work for me. - Sevan Golnazarian
Check the answer by fullstack.studio below. The require import solved the issue for me. I'm still looking for official docs that list which modules need to be imported using require vs define. - Sevan Golnazarian

1 Answers

1
votes

I think it's time to learn the N/query ;)

As client side script you may load the N/search using require.

/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define([],
    function () {
        function loadSearch(callback) { require(['N/search'], search => { callback(null, search); }); }
        function pageInit(context) {
            try {
                loadSearch((error, search) => {
                    if (!error) {
                        let c_data = search.lookupFields({
                            type: search.Type.CUSTOMER,
                            id: "4390463",
                            columns: ["altname", "email", "address"]
                        });
                        console.log('c_data', c_data);
                    }
                });
            } catch (e) {
                console.error('loadSearch', e);
            }
        }
        return {
            pageInit: pageInit
        };
    });