Getting the following error when trying to call a ...
# suitescript
m
Getting the following error when trying to call a client script function from a button.
Uncaught TypeError: mod.reinstateAgency is not a function
Adding client script like this.
Copy code
scriptContext.form.clientScriptModulePath = "/SuiteScripts/xxxx-scripts/record-automations/xxxx-cl-suspend-reinstate-agency.js";```
Adding button like this.
Copy code
scriptContext.form.addButton({
    id: "custpage_reinstate_button"
    , label: "Reinstate"
    , functionName: "reinstateAgency"
});
Client script has this to just test whether I can call the function.
Copy code
/**
 * @NApiVersion 2.1
 */
define([]
    , () => {
        return {
            reinstateAgency: () => {
                window.open("<https://google.com>");
            }
            , suspendAgency: () => {
                window.open("<https://google.com>");
            }
        };
    });
b
you probably want to use your browsers debugger for this one
the code you shared looks fine, my guess would be that whatever client script being loaded is not the one you expect
m
When I search for the functions in the browser debugger they show up, but of course never hit.
b
setup the debugger to run on caught exceptions
m
Never tried that...let me try and set that up.
I notice the only method in the object
mod:
is for another button. What's strange is that I get the same error when I try and do this from the button directly.
Copy code
scriptContext.form.addButton({
    id: "custpage_suspend_button"
    , label: "Suspend TEFAP"
    , functionName: "window.open(\"<https://google.com>\")"
});
Something similar is in the sample script in Netsuite help except that the url is an actual SuitLet url instead of Google.
Can
scriptContext.form.clientScriptModulePath
only be called once on a record?
Weird I added the same function to another client script that is added and it works perfectly.
w
I’ve seen that if you add at least one clientscriptmodulpath through ue, all custom buttons will get extra code wrapped around the functionName. So after that, you can't use “inline” code in the functionName parameter. It may be that all the buttons added by the same ue gets this code wrapped around them. Inspect the button and see what the actual onClick does