Cannot add Client Script 2.1 to a Transaction Form

I am unable to wrap my head around why this won’t work. We are currently using a V2.0 client script to capture signatures on our invoices. An update to Chrome broke that function a while ago and was fixed before I finished an updated version. Now that it is finished and working flawlessly from a User Event Script button, I am trying to replace the script file under Custom Code and I keep getting the error message “SuiteScript version 2 file used for form scripts must implement client script type”. This obviously is already a Client Script. I have even tried removing the existing script, saving, and then edit and adding the new one, and I still get the error message.

Rookie Asked on September 19, 2024 in SuiteScript.
Add Comment
4 Answer(s)

Hi there

Without seeing any of the code it’s bit hard to troubleshoot.  First and foremost, are you defining the script type at the beginning of your script?

/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
 

 

 

 

Rookie Answered on September 19, 2024.
Add Comment

Oops, thought I added that in a 2nd post. The only thing missing is the scope, but none of our scripts have that. I did try simply changing from 2.1 to 2.0 and I get an error as my code is using ES6 features. The script works flawlessly, I have been using it for months to ensure there are no issues in the field. The only thing is I now want to remove the UserEvent button I added for testing and move it to a custom action on the form. That’s where the error comes in to play.

/**
* @NApiVersion 2.1
* @NScriptType ClientScript
*/
 
function closeSignatureWindow(signedname, imgData){
    sessionStorage.setItem("signedname", signedname);
    sessionStorage.setItem("imgData", imgData);
    this.parent.sigwin.close();
}
 
define(['N/currentRecord', 'N/ui/message', 'N/ui/dialog'], function (currentRecord, message, dialog) {
 
    function pageInit(context) {
        var objRecord = currentRecord.get();
        var imgvalue = objRecord.getValue({
            fieldId: 'custbodysigdata'
        });
        if (imgvalue.length <= 40) {
            imgData = 'iVBORw0KGgoAAAANSUhEUgAAAHwAAAB8CAIAAAAkfEPpAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAERSURBVHhe7dAxAQAwEAOh+jeduvhbQAJvnJMekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6Qfm77q5OGTspOFOwAAAAASUVORK5CYII=';
            var record = currentRecord.get();
            record.setValue({
                fieldId: 'custbodysigdata',
                value: imgData,
                ignoreFieldChange: true,
                forceSyncSourcing: true
            });
            var superSaved = objRecord.getValue({
                fieldId: 'custbody_supersaved'
            });
            if (superSaved) {
                onButtonClick();
            }
        }
    }
 
    function endDemo() {
        LcdRefresh(0, 0, 0, 240, 64);
        LCDSetWindow(0, 0, 240, 64);
        SetSigWindow(1, 0, 0, 240, 64);
        KeyPadClearHotSpotList();
        SetLCDCaptureMode(1);
        SetTabletState(0);
        ClearTablet();
    }
 
    function onButtonClick() {
        try{
            sessionStorage.setItem("signaturecomplete", "false");
            var sigwebnotinstalled = sessionStorage.getItem("sigwebnotinstalled");
            var isMobile = false;
            if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
                var isMobile = true;
            }
            if(isMobile == true){
                Ext.onReady(function() {
                    sigwin = Ext.create('Ext.Window', {
                    title: 'Signature Capture',
                    height: 300,
                    width: 700,
                    minWidth: 150,
                    minHeight: 550,
                    layout: 'fit',
                    itemId : 'popUpWin',
                    modal:true,
                    shadow:false,
                    resizable:false,
                    constrainHeader:true,
                    items: [{
                        xtype: 'box',
                        autoEl: {
                                 tag: 'iframe',
                                 src: '[REDACTED].html',
                                 frameBorder:'0'
                        }
                    }],
                    listeners:{
                        beforeclose: function () {
                            if (sigwebnotinstalled == "false") {
                                endDemo();
                                }
                            postData();
                            if (sigwebnotinstalled == "false") {
                                endDemo();
                                }
                            }
                        }
                    });
                });
                sigwin.show();
            } else if (isMobile == false){
                Ext.onReady(function() {
                    sigwin = Ext.create('Ext.Window', {
                    title: 'Signature Capture',
                    height: 300,
                    width: 700,
                    minWidth: 150,
                    minHeight: 550,
                    layout: 'fit',
                    itemId : 'popUpWin',
                    modal:true,
                    shadow:false,
                    resizable:false,
                    constrainHeader:true,
                    items: [{
                        xtype: 'box',
                        autoEl: {
                                 tag: 'iframe',
                                 src: '[REDACTED].html',
                                 frameBorder:'0'
                        }
                    }],
                    listeners:{
                        beforeclose: function () {
                            if (sigwebnotinstalled == "false") {
                                endDemo();
                                }
                            postData();
                            if (sigwebnotinstalled == "false") {
                                endDemo();
                                }
                            }
                        }
                    });
                });
                sigwin.show();
            } else {
                Swal.fire({
                    text: 'An error has occurred while initializing the signature capture window.',
                    icon: 'error',
                    allowEscapeKey : false,
                    allowOutsideClick: false,
                    allowEnterKey: false,
                    confirmButtonText: 'Ok'
                });
            }
        } catch (e) {
            log.error({
                title: 'openSignatureWindow',
                details: e
            });
        }
    }
 
    function postData(){
        var sigcheck = sessionStorage.getItem("signaturecomplete");
        if (sigcheck == "true") {
            var signedname = sessionStorage.getItem("signedname");
            var imgData = sessionStorage.getItem("imgData");
            var record = currentRecord.get();
                record.setValue({
                    fieldId: 'custbodysigdata',
                    value: imgData,
                    ignoreFieldChange: false,
                    forceSyncSourcing: true
                });
            var currentMemo = record.getValue({
                fieldId: 'custbody4'
                });
            var newMemo = currentMemo.concat (" | Signed by: ", signedname);
                record.setValue({
                    fieldId: 'custbody4',
                    value: newMemo,
                    ignoreFieldChange: false,
                    forceSyncSourcing: false
                });
            message.create({
                title: "Signature Captured!",
                message: 'The signature has been captured successfully.',
                type: message.Type.CONFIRMATION,
                duration: 10000
            }).show();
        } else {
            var options = {
                title: "Error",
                message: "The signature was not captured successfully. Please Try Again."
            };
            dialog.alert(options);
        }
    }
 
    function clearButtonHit(context) {
 
        imgData = 'iVBORw0KGgoAAAANSUhEUgAAAHwAAAB8CAIAAAAkfEPpAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAERSURBVHhe7dAxAQAwEAOh+jeduvhbQAJvnJMekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6QHpAekB6Qfm77q5OGTspOFOwAAAAASUVORK5CYII=';
 
        var record = currentRecord.get();
        record.setValue({
            fieldId: 'custbodysigdata',
            value: imgData,
            ignoreFieldChange: true,
            forceSyncSourcing: true
        });
    }

The rest of the code not shown is from this as it is not my code to modify.

    //SigWebTablet JavaScript File for SigWeb
    //
    //Version – 1.0.4.0

Rookie Answered on September 20, 2024.
Add Comment

This is the error I am getting whenever I try to change the script from the old 2.0 script to the new 2.1 script. As originally stated, I have tried removing the script file, saving, editing, and selecting the new one.

RE: Cannot add Client Script 2.1 to a Transaction Form

And this is the error I get if I simply change the version from 2.1 to 2.0 in the editor.

RE: Cannot add Client Script 2.1 to a Transaction Form

From what I have learned from other scripts we use, this error is common with ES6 style code.

Rookie Answered on September 20, 2024.
Add Comment

I narrowed the errors down to being caused by having the sigwebtablet.js file directly in the file for the endDemo() function, since I could not find a supported method to use the functions externally. However, we are now moving away from Netsuite to a new system and to top it off, 2025.1 broke the onButtonClick() function and can’t handle the Ext portion that generates the pop up window. Since we are moving away from Netsuite, I no longer have the need to further develop this.

Thank you!

Rookie Answered on February 17, 2025.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   SuiteMigration   Become a Sponsor