Whenever I try to create a script record it throws...
# suitescript
s
Whenever I try to create a script record it throws this error: SuiteScript 2.0 entry point scripts must implement a script type function" Error I put in an entry point function and even if it doesn't do anything it throws this error.
s
Might as well post your script assuming its tiny and not doing much, probably something small
j
Did you remember to put the functions in the
return
at the end of your file?
e.g.
Copy code
return {
		
		pageInit: pageInit
		
	}
s
@jen yes I did it
@Sandii I will post. It's not that short. I copied the base from other scripts and just made a few changes. The other scripts also have this problem, but I included pageInit to see if it worked, but not.
@Sandii
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */

define(['N/record', 'N/currentRecord', 'N/search', 'N/url', './JSPMStatus.js', './JSPrintManager.js'],

    function (record, currentRecord, search, url, JSPMStatus, JSPrintManager) {
        function pageInit(){};

        var quantity = '';
        var dataInicio = '';
        var tranID = '';
        var lineFeed = "\x0A";
        var cmds = '';
        const JSPM;

        JSPM.JSPrintManager.auto_reconnect = true;
        JSPM.JSPrintManager.start();
        JSPM.JSPrintManager.WS.onStatusChanged = function () {

        };

        function JSPMStatus() {
            const JSPM;
            if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.Open)
                return true;
            else if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.Closed) {
                alert('JSPrintManager (JSPM) is not installed or not running! Download JSPM Client App from <https://neodynamic.com/downloads/jspm>');
                return false;
            } else if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.BlackListed) {
                alert('JSPM has blacklisted this website!');
                return false;
            }
        }

        


        function print(o) {
            const JSPM;
            
            try {

                if (JSPMStatus()) {
                    //Create a ClientPrintJob
                    var cpj = new JSPM.ClientPrintJob()

                    cpj.clientPrinter = new JSPM.DefaultPrinter()

                    var recordPrint = currentRecord.get()

                    var id = recordPrint.getValue({
                        fieldId: 'custpage_numero_pedido_trabalho'
                    });

                    var workOrder = record.load({
                        type: 'workorder',
                        id: id,
                        isDynamic: true
                    });

                    dataInicio = workOrder.getValue({
                        fieldId: 'startdate'
                    });

                    tranID = workOrder.getValue({
                        fieldId: 'tranid'
                    })

                    var suiteletURL = url.resolveScript({
                        scriptId: 'customscript_rsc_sl_etiqueta_caixa_indiv',
                        deploymentId: 'customdeploy_rsc_sl_etiqueta_caixa_indiv'
                    });


                    //Set content to print...
                    //Create Zebra EPL commands for sample label

                    cmds += lineFeed;
                    cmds += 'CT~~CD,~CC^~CT~';
                    cmds += lineFeed;
                    cmds += '^XA~TA000~JSN^LT0^MNW^MTD^PON^PMN^LH0,0^JMA^PR6,6~SD29^JUS^LRN^CI0^XZ~DG000.GRF,01280,020,:::::::::O070I07F0K07F01FJFC0I070,N03F8007FFE80I0HF81FJFC0H03F0,N0HFI0JF80H01FF01FJFC0H0HF0,M0HFE003FA3F80H03FE03FJF800FFE0,L03FFE001F007C0H07FE0J07C003FFE0,K01FHFE003F00FC003FFE0J0F801FHFE0,K01FCFC001F00FC007F7C0I01F001FCFC0,K03E0F8003F83F800FEFE0I0FE003E0F80,K0101F80H07FFE001F0FC0H01FC00101F80,M03F80H0IF8007F0F80H03F80I03F80,M01F0H03FHFC00FC1F80H07F0J01F,M03F800FE07F03F83F80H0FE0J03F80,M03F001FC03F03F01F0I0FC0J03F,M07E003F803F8FKF801F80J07E,M07E001F003F0FKFH01F0K07E,M0FE003F807F0FKFH03F0K0FE,M07C001FC07E0I07E0H07E0K07C,M0FE0H0JFC0I0FE0H0FE0K0FE,L01FC0H07FHFK0FC0H0FC0J01FC,L01F80I0BF80J0FC0H0F80J01F8,,:::::::::::::::::::::::::::::::::';
                    cmds += lineFeed;
                    cmds += '^XA';
                    cmds += lineFeed;
                    cmds += '^MMT';
                    cmds += lineFeed;
                    cmds += '^PW320';
                    cmds += lineFeed;
                    cmds += '^LL0102';
                    cmds += lineFeed;
                    cmds += '^LS0';
                    cmds += lineFeed;
                    cmds += '^FT96,64^XG000.GRF,1,1^FS';
                    cmds += lineFeed;
                    cmds += '^FT13,45^A0N,25,52^FH\^FD' + tranID + '^FS';
                    cmds += lineFeed;
                    cmds += '^FT16,70^A0N,25,52^FH\^FD' + dataInicio + '^FS';
                    cmds += lineFeed;
                    cmds += '^PQ1,0,1,Y^XZ';
                    cmds += lineFeed;
                    cmds += '^XA^ID000.GRF^FS^XZ';

                    cpj.printerCommands = cmds
                    //Send print job to printer!
                    cpj.sendToClient()

                    setTimeout(function () {
                        window.location.href = suiteletURL;
                    }, 4000);

                }
            }
            catch (error) {
                console.log("cagou", error)
            }
        }


        function fieldChanged(context) {

            var currentRecord = context.currentRecord

            var tipo = context.fieldId
            try {
                if (tipo === 'custpage_numero_pedido_trabalho') {

                    var id = currentRecord.getValue({
                        fieldId: 'custpage_numero_pedido_trabalho'
                    });

                    var workOrder = record.load({
                        type: 'workorder',
                        id: id,
                        isDynamic: true
                    });

                    tranID = workOrder.getValue({
                        field: 'tranid'
                    })

                    quantity = workOrder.getValue({
                        fieldId: 'quantity',
                    })

                    currentRecord.setValue({
                        fieldId: 'quantity',
                        value: quantity
                    });

                    currentRecord.setValue({
                        fieldId: 'tranid',
                        value: tranID
                    })

                }
            } catch (error) {
                log.error('erro', error)
            }
        }

        return {
            fieldChanged: fieldChanged,
            pageInit: pageInit,
            print: print
        }
    });
s
immediately
const JSPM
makes no sense, you can't initialize a
const
without a value
JSPM.JSPrintManager.auto_reconnect
does not make any sense
you also consistently redefine that same
const
as nothing, which seems illogical
j
Not sure why you even have a pageInit here, you don’t need that since you have fieldChanged.