Can a SS 1.0 and 2.0 Client Side script exist on t...
# suitescript
j
Can a SS 1.0 and 2.0 Client Side script exist on the same record?
m
As separate scripts or in a single script?
j
Separate
m
Yep
j
Yeah I thought so..trying to add a new SS 2.0 client side script, but getting an Mismatched anonymous define() module error in the browser console.
If I remove the 2.0 deployment the error goes away
b
obviously make sure the script you are adding doesn't do anything wrong/weird
outside that, make sure the 1.0 scripts dont have libraries that use a umd module pattern
j
@battk as always appreciate your help. The initial problem seemed to come from sweetalert being included into the page using NS require in an anonymous function. When removed a similar error came up in a pageInit 2.0 client side script. I was trying to do a search.lookupFields. It doesn't seem I can use a NetSuite module other than current record in pageInit. When I moved search.lookupFields call to fieldChanged or saveRecord no errors. Is that expected in pageInit that I can't use a NetSuite module like N/search?
b
You get that mismatched define error when something calls define without a require higher in the stack
First required module after the mismatched define causes error
j
Trying to break it down so deployed to transaction with no other scripts, and I found that if both a lib module referenced in the client script define and the client script itself both referenced the N/search module I would get the error. Took out of the N/search module in the define statement of the client script (not needed) and then the client script works with no error on the call it makes to the lib file that actually does lookupFields does that make sense?
b
What do the scripts look like
j
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define(['N/search','./mtg_lib_credit_policy.js'],
/**
 * @param {search} search
 */
function(search,mtcpe) {
    
    /**
     * Function to be executed after page is initialized.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
     *
     * @since 2015.2
     */
    function pageInit(scriptContext) {
        mtcpe.init(scriptContext.currentRecord);
    }
   
    return {
        pageInit: pageInit,
        fieldChanged:fieldChanged
    };
    
});
Copy code
And then the lib define(['N/search'],
/**
 * @param {search} search
 */
function(search) {
    
   
    var _currentRecord = null;
     
    function loadCustomerFields(){
        
        // Lookup the override flags from the customer and the customers classification.
        var custFields = search.lookupFields({
            type:'customer',id:'1338830',
            columns:['custentity_mtg_poitems_any_pmtmthd','custentity_mtg_donotapply_credit_policy','custentity_mtg_secondary_class']
        });
        console.log(custFields);
        
    }
   
    return {
        /**
         * Initializing the library
         * @param {NSRecord} paramCurrRecord netsuite record object representing a sales order or estimate
         */
        init:function(paramCurrRecord,paramSearch){
            
            _currentRecord = paramCurrRecord;
            loadCustomerFields();
            
        }
    };
    
});
b
works normally for me
had to remove the fieldChanged and changed the search lookup to look for more standard fields
you may want to see if something like a custom field is adding scripts inline
j
You're talking about an inlineHTML or something be injected on beforeLoad?
b
inline html field adding <script>
i wouldn't expect a beforeLoad if you disabled other scripts
j
Ok thanks for your time. Happy to hear the concept of what I'm doing should work just need to find the offending bit.
Found the offending bit it was lodash.js. I've delayed it's loading until just before it's needed (after pageInit) and that gets rid of the issue. Thanks again!