Hi All, Has anybody found a way in a suitelet to ...
# suitescript
t
Hi All, Has anybody found a way in a suitelet to add a client script function to a href rather than a button. The script call works with
Copy code
sublist.addButton({
                id: 'btnTestGoBack',
                label: 'Test',
                functionName: "callProcess('7', 'urlOne')"
            });
but doesnt work when you do
Copy code
'<a href="#" onclick="callProcess(\'7'\, \'urlOne\')">Start Process</a>'
Thanks Tim
b
what does the client script look like
t
The client script is calling another suitelet nothing specail
Copy code
function callProcess(batchId, passedUrl) {
            alert('Requesting Processing');
            let response = nsHttps.post.promise({
                url: passedUrl,
                body: JSON.stringify({
                    op: 'srtRate',
                    headerRecordId: batchId
                })
            }).then(response => {
                if (response?.code === 200) {
                    alert('Submitted');
                } else {
                    log.error({title: 'callProcess', details: {response: response} });
                }
            }).catch(e => { log.error({title: 'callProcess', details: {e: e} });});
        }
b
still not really enough
cant tell the scope from the function
take a look at the onclick of the button
t
Copy code
define(['N/https', 'N/log'],

    (nsHttps, log) => {

        /**
         * Module Description...
         *
         * @type {Object} module-name
         *
         * @copyright 2023 SuiteFunction
         * @author Tim Pilgrim <tim@suitefunction.com>
         *
         * @NApiVersion 2.1
         * @NModuleScope SameAccount

         * @NScriptType ClientScript
         */
        var exports = {};

        /**
         * pageInit event handler; executed when the page completes loading or when the form is reset.
         *
         * @gov XXX
         *
         * @param {Object} context
         * @param {string} context.mode - The access mode of the current record.
         * @param {CurrentRecord} context.currentRecord - The record in context
         */
        function pageInit(context) {
            // TODO
        }

        function callProcess(batchId, passedUrl) {
            alert('Requesting Processing');
            let response = nsHttps.post.promise({
                url: passedUrl,
                body: JSON.stringify({
                    op: 'srtRate',
                    headerRecordId: batchId
                })
            }).then(response => {
                if (response?.code === 200) {
                    alert('Submitted');
                } else {
                    log.error({title: 'callProcess', details: {response: response} });
                }
            }).catch(e => { log.error({title: 'callProcess', details: {e: e} });});
        }


        exports.pageInit = pageInit;
        exports.callProcess = callProcess;
        return exports;
    });
b
and compare it to your onclick
the button's onclick is probably using require, which is why it has access to callProcess
you anchor does not, which is why it does not and defaults to the global scope, which does not have a callProcess function
t
yeah it has way more in it. I was wondering if anyone knew how to generate that.
Copy code
onclick="var  rConfig =  JSON.parse( '{}' ) ; rConfig['context'] = '/SuiteScripts/SuiteFunction/Batching/SF_createBatch_cs'; var entryPointRequire = require.config(rConfig); entryPointRequire(['/SuiteScripts/SuiteFunction/Batching/SF_createBatch_cs'], function(mod){ try{    if (!!window)    {        var origScriptIdForLogging = window.NLScriptIdForLogging;        var origDeploymentIdForLogging = window.NLDeploymentIdForLogging;        window.NLScriptIdForLogging = 'customscript_sf_create_batch';        window.NLDeploymentIdForLogging = 'customdeploy_sf_create_batch';    }mod.callProcess('7', 'urlOne');}finally{    if (!!window)    {        window.NLScriptIdForLogging = origScriptIdForLogging;        window.NLDeploymentIdForLogging = origDeploymentIdForLogging;    }} }); return false;"
but I can just hard code it and hope netsuite dont screw with the ui enough that it breaks
b
you really only need to use require
t
sorry doing this between calls, thanks @battk, simplified to just the require and it all works!