2

/**

  • @NApiVersion 2.x

  • @NScriptType ClientScript */ define(["N/record", "N/url",'N/currentRecord'], function (record, url,currentRecord) { function onclick_callforSuitelet(){} function pageInit() {

     var record = currentRecord.get();
     var recordId = record.id;
     var recordType = record.type;
     log.debug("recId", recordId);
     log.debug("recType", recordType);
     var suitletURL = url.resolveScript({
         scriptId:'customscriptss_suiteletbutton',
         deploymentId:'customdeployss_suiteletbutton',
         returnExternalUrl: true,
         params: {
             recId: recordId,
             recType: recordType
         }
    

    }); log.debug("suitletURL", suitletURL);

} return{ pageInit:pageInit, onclick_callforSuitelet:onclick_callforSuitelet } });

1 Answers1

2

You could do it all in the UserEventScript like:

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
*/
define(["N/url"], function (url) {

    function beforeLoad(context) {

        var form = context.form

        var sl_url = url.resolveScript({
            scriptId: 'SCRIPT_ID',
            deploymentId: 'DEPLOYMENT_ID'
        });

        form.addButton({
            id: 'custpage_custombuttonid',
            label: 'Your Label',
            functionName: '(function() { window.location = "' + sl_url + '" })();'
        });
    };

    return {
        beforeLoad: beforeLoad
    };
});

Or if that doesn't work, with a combination of a UserEvent script and a ClientSide script

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
*/
define(["N/url"], function (url) {
  function beforeLoad(context) {
      var form = context.form
      form.clientScriptModulePath = 'SuiteScripts/SDF/YOUR_PATH_TO/client_script.js';

      var sl_url = url.resolveScript({
          scriptId: 'SCRIPT_ID',
          deploymentId: 'DEPLOYMENT_ID'
      });

      form.addButton({
          id: 'custpage_custombuttonid',
          label: 'Your Label',
          functionName: 'redirect("' + sl_url + '");'
      });
  };

  return {
      beforeLoad: beforeLoad
  };
});

/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
*/
define([], function () {
  function redirect(url) {
      window.location = url;
  }
  return {
    redirect: redirect
  };
});

W.S.
  • 1,401
  • 1
  • 7
  • 9
  • Thanks for helping me, but I need one more thing to know, the thing you have given is when I click that button it is going on to another page which means the records I filled in on that page may not be saved, my need is to that button click it should be open like a pop up suitelet on the same pageitself. – Netsuite user Oct 17 '22 at 07:31
  • You could create a dialog with the N/ui/dialog module and display to content within that dialog in an iframe. However displaying it properly will be difficult. Another option would be to use the regular `` html element (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog), or create a React/Vue component which would show it within a modal/dialog. Or another and maybe easier solution would be to open a new tab instead of changing the location, like `window.open(url, '_')` – W.S. Oct 17 '22 at 09:12