Home page for JE create/edit/view screens.

Jira Code: TRS-115

Home page screen to further creates Journal view and edit screens. A user can add another button by adding script id and deployment id into the main object defined in the top. Instead of the default button, we implemented inner HTML with bootstrap libraries.

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 * @NModuleScope SameAccount
 */

/* Script Description
* Create a page which contain several button, clicking on each button will navigate into another page
  based on the url resolved from the main array.

******************************************************************************************************
 Trust bridge
******************************************************************************************************
* Date: 28-06-19
* MN
* Author: Jobin & Jismi IT Services LLP*/
/*****************************************************************************************************/



var buttonArray = [{
        "Name": "Journal Entry",
        "SuitletId": "customscript_trus74_sl_create_je_page",
        "DeploymentId": "customdeploy_trus74_sl_create_je_page",
        "Link": ""
    },
    {
        "Name": "Journal Entry",
        "SuitletId": "customscript_trus74_sl_create_je_page",
        "DeploymentId": "customdeploy_trus74_sl_create_je_page",
        "Link": ""
    },
    {
        "Name": "Journal Entry",
        "SuitletId": "customscript_trus74_sl_create_je_page",
        "DeploymentId": "customdeploy_trus74_sl_create_je_page",
        "Link": ""
    },
    {
        "Name": "Journal Entry",
        "SuitletId": "customscript_trus74_sl_create_je_page",
        "DeploymentId": "customdeploy_trus74_sl_create_je_page",
        "Link": ""
    },
    {
        "Name": "Journal Entry",
        "SuitletId": "customscript_trus74_sl_create_je_page",
        "DeploymentId": "customdeploy_trus74_sl_create_je_page",
        "Link": ""
    },{
        "Name": "Journal Entry",
        "SuitletId": "customscript_trus74_sl_create_je_page",
        "DeploymentId": "customdeploy_trus74_sl_create_je_page",
        "Link": ""
    },
];




define(['N/email', 'N/file', 'N/record', 'N/runtime', 'N/search', 'N/ui/serverWidget', 'N/url'],
    /**
     * @param {email} email
     * @param {file} file
     * @param {http} http
     * @param {https} https
     * @param {record} record
     * @param {runtime} runtime
     * @param {search} search
     * @param {serverWidget} serverWidget
     */
    function(email, file, record, runtime, search, serverWidget, url) {



        /**
         * Definition of the Suitelet script trigger point.
         *
         * @param {Object} context
         * @param {ServerRequest} context.request - Encapsulation of the incoming request
         * @param {ServerResponse} context.response - Encapsulation of the Suitelet response
         * @Since 2015.2
         */
        function onRequest(context) {

            try {

                var html = '';
                html += '<div class="container">' + ' <div class="row">';

                html += '<script> var librarySource = [{ type: \'css\', src: \'https://cdnjs.cloudflare.com/ajax/libs/bootswatch/4.3.1/cerulean/bootstrap.min.css\'}, { type: \'js\', src: \'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js\'}, { type: \'js\', src: \'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js\'}, { type: \'js\', src: \'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js\'} ]; function synchronousLoadScript(url) {try {var script = document.createElement("script"); script.src = url; script.type = "text/javascript"; script.async = false; } catch (err) {console.log(err); } } /*To load css stylesheet synchronously*/ function synchronousLoadStyleSheet(url) {try {var head = document.getElementsByTagName(\'head\')[0] || document.documentElement; var script = document.createElement("link"); script.href = url; script.rel = "stylesheet"; script.async = false; head.appendChild(script); } catch (err) {console.log(err); } } function loadAllDependencies() {var loadCSS = synchronousLoadStyleSheet(librarySource[0].src); for (var i = 1; i < librarySource.length; i++) {var loadJS = synchronousLoadScript(librarySource[i].src); } } loadAllDependencies(); </script>';

                for (var i = 0; i < buttonArray.length; i++) {

                    currentButton = buttonArray[i];

                    // TO GET THE URL

                    var suiteletURL = url.resolveScript({ scriptId: currentButton.SuitletId, deploymentId: currentButton.DeploymentId, returnExternalUrl: false });

                    buttonArray[i].Link = suiteletURL;

                    //CREATE EACH BUTTON
                    html += '<div class="col-xs-6 col-sm-4 mt-5"><button type="button" class="btn btn-dark btn-lg" onclick="window.open(\''+currentButton.Link+'\')">'+currentButton.Name+'</button></div>';


                }

                html += '</div></div>';

                var form = serverWidget.createForm({
                    title: 'HomePage'
                });

                log.debug("html", html);

                var inlineHTML = form.addField({
                    id: '_custbutton' + i,
                    type: serverWidget.FieldType.INLINEHTML,
                    label: 'Inline HTML SCRIPT'
                });

                inlineHTML.defaultValue = html;


                context.response.writePage(form);

            } catch (e) { log.debug("Main Function error", e); }
        }
        return {
            onRequest: onRequest
        };

    });


Leave a comment

Your email address will not be published. Required fields are marked *