RE: 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.
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