You are not crazy, SS2.0 External Suitelets don’t run clientside code

You are not crazy, SS2.0 External Suitelets don’t run clientside code

Hey guys, just letting you know that I encountered an issue recently. I was trying to create a Suitelet “Available without Login” that uses a form and I was attaching a button and a clientscript to it, but guess what? The button doesn’t work. I checked the console and every time I call the button I get “require is not defined” error:

8pJdqVF

So I stripped the suitelet to the most barebones version and I still got the error. I verified with others and it seems to be a defect from SS2.0 External Suitelets.
At the end of the day I was able to run the code by hacking the dom like so:

and as the clientscript file I have this:

Totally not recommended, but just throwing it out there.

  • Adrian

    Thanks for posting this, How about Internal 2.0 Api Suitelets? I’m new to NetSuite, and Im trying to use the onFieldChange Entry point of a client script within a Suitelet form using “form.clientScriptFileId = scriptId;” but I don’t seem to get anything to happen.

    • Hey, sorry for not replying earlier, I just came back from a business trip. What you are describing is possible but tricky because you need to have a clientscript record even though you are setting the file id.

      So basically what you need to do is:
      – Create your clientscript file in 2.0. The contents should look like so: https://pastebin.com/YpuYtbH6
      – The script you create must look like this:
      https://uploads.disquscdn.com/images/52cff6db9cc5c80bf5ec07f676a484948c461a37f427de1755ab21032f260ec1.jpg
      – Skip the deployment part, you don’t need to create deployments for that clientscript.
      – Locate the clientscript file in the file cabinet and get the internal id, this should be an integer.
      – Finally add the clientscript by internal id to your Suitelet: form.clientScriptFileId = 12345; //12345 is the internal id of the clientscript file.

      Remember that this only works on internal suitelets.

      • Adrian

        Thanks for getting back to me Adolfo, I tried your method and even just used your example client script and I still get nothing. I put up some of my code on the pastebin: https://pastebin.com/dJx5nfYm

        • That code looks good. Sometimes the browser caches the page so I would try to logout and log back in and try it again on a different window. If not then I don’t know what could have gone wrong, maybe check the browser console and see if there are any errors happening when you do a field change. Also, make sure the js file with internal id of 399 is the one linked in the clientscript record.

          • Adrian

            Still nothing. Its strange that I don’t even get an error. I ended up refactoring my entire suitelet (and Client script to 1.0) and everything works great. Not sure exactly what went wrong before.

          • Adolfo Garza

            Thanks for reporting that. I will keep it in mind in case I run into that issue in the future, maybe it was a Netsuite version issue. I’m glad you were able to make it work in 1.0.

          • Adrian

            No Problem. Oh and one more thing I did do differently, was both scripts are one .js file just split into two script records. Not sure if that had anything to do with it as well.

  • Felipe Chang

    Try writing a bracketed function inside the function name, like so:

    form.addButton({
    id : ‘custpage_mybutton’,
    label : ‘MyButton’,
    functionName : ‘(alert(“foo”))’
    });

    The onclick event will display as: (alert(“foo”))() .

    I’ve used this on user event buttons, it might work.

  • Nich Twatwunnaphong

    Is this supposed to work with require?

    I tried something like this, but I get the same error:

    $(‘custpage_mybutton’).onclick = function(){ runButtonClickAction(); }

    function runButtonClickAction(){
    require([‘N/currentRecord’], function (currentRecord) {
    var recCurrent = currentRecord.get();
    console.log(recCurrent);
    });
    }

    I couldn’t get any SS 2.0 code with modules to work without login.

    SS 1.0 get/set values still seemed to work though.

    • I don’t think 2.0 modules would load externally but I haven’t tested. I think you might need to get creative and pass data through the Suitelet so it’s processed serverside.

  • Arudian

    Any idea if that has been corrected ?
    I like your way around it, but it won’t work as i need to access records in my clientscriptss records in my clientscript